Page toolsPDF
Merge files, delete, reorder, rotate, duplicate, replace, extract and split pages, resize them to a paper size, add page numbers, impose booklets and more, from the Pages tab, the organizer or code, with undo and correct annotation and form placement.
Page tools change the pages of the open document: their order, their number, their size and what is printed on them. There are four places to reach them, and they all run the same commands.
| Where | What you see |
|---|---|
| Pages tab | A tab in the top toolbar, between Edit and Forms. Choosing it opens a row of buttons, each with an icon and its name. |
| Thumbnails panel | The sidebar panel with one small picture per page. A row of quick icons sits above the list, and a right-click on a thumbnail opens a menu with every page command. |
| Organizer | A window that fills the viewer with a grid of large thumbnails, made for reordering many pages. |
| Command palette | Press F1 and type pages. Every page command is listed as Pages: … with its shortcut. |
enablePageTools: false removes all four. readOnly: true does the same. A document whose permissions do not allow assembling shows the buttons greyed out, and their tooltip names the missing permission.
The Pages tab#
- Choose Pages in the top toolbar. A second row appears under the toolbar.
- Read the row from left to right: Organize, Merge files…, Insert, then Delete, Rotate left, Rotate right, Duplicate, Extract, Split…, Replace…, Move to…, Reverse, then Crop…, Resize…, Page numbers… and More. On a narrow screen the names are hidden and only the icons stay; the names remain in the tooltips.
- Hold the pointer over a button to see its tooltip with the keyboard shortcut, for example Delete (Alt+Shift+Delete).
- Choose a button. It acts on the thumbnails that are selected in the thumbnails panel, or on the page you are looking at when the panel is closed or only one thumbnail is selected.
A name that ends in … opens a dialog first. The dialog says which pages will be changed, for example Pages 2-4 of the document will be changed.
| Button | What it does |
|---|---|
| Organize | Opens the organizer |
| Merge files… | Opens the merge dialog |
| Insert | A menu: Blank page, From PDF…, From images…, From clipboard image. The new pages are placed after the last target page. |
| Delete | Removes the pages. The last page of a document cannot be deleted. |
| Rotate left, Rotate right | Turns the pages by 90° |
| Duplicate | Inserts a copy of the pages after the last of them |
| Extract | Asks whether to Delete the pages after extracting, then downloads the pages as a new file |
| Split… | Opens the split dialog |
| Replace… | Choose a PDF and, if you like, a page range of it; those pages take the place of the target pages |
| Move to… | Type the new position of the first moved page and press Enter |
| Reverse | Reverses the selected pages, or the whole document when fewer than two are selected |
| Crop… | Opens the crop dialog |
| Resize… | Opens the resize dialog |
| Page numbers… | Opens the page number dialog |
| More | A menu: Remove page numbers, Page labels…, Page boxes…, Delete blank pages, Interleave with a file…, Multiple pages per sheet…, Compress and download… |
After each command the viewer announces the result to screen readers, for example Moved 2 pages to position 5 or Deleted 1 page. Every command is one step for Undo (Ctrl+Z).
Select several pages#
- Open the sidebar and choose the thumbnails panel.
- Click a thumbnail. Hold
Ctrland click to add or remove single pages; holdShiftand click to add a range. - Choose a button in the Pages tab, or right-click one of the selected thumbnails and pick a command from the menu.
With the keyboard, move through the thumbnails with the arrow keys, extend the selection with Shift and an arrow key, and open the menu with Shift+F10 or the context-menu key. Alt+ArrowUp and Alt+ArrowDown move the focused page, and Delete removes the selection. Thumbnails can also be dragged to a new place; a line shows where they will land.
Signed documents#
Any change to the pages of a signed document invalidates its signatures. The first time you run a command that changes pages, a dialog titled This document is signed asks whether to continue. Cancel leaves the document untouched; Change anyway runs the command and does not ask again for this document. Extracting, splitting and the other commands that only produce a new file do not ask.
The organizer#
Open it with Organize in the Pages tab, the last icon above the thumbnails, Organize pages in the menu, or Alt+Shift+O. Only the thumbnails in view are drawn, so a document with hundreds of pages opens at once.
What is on screen, from top to bottom:
- A toolbar with groups: Undo and Redo; Selection (Select all, Odd pages, Even pages, Invert selection, Clear selection and a box for a typed range such as
1-3, 7, 10-); Pages (Rotate left, Rotate right, Delete, Duplicate, Extract, Reverse order); Insert (Blank page, From a PDF file, From image files); Document (Resize pages, Page boxes, Page labels, Split document); Second document; and a Thumbnail size slider. - A status line such as 3 pages selected · 12 pages.
- The grid. Each cell shows the page, with its page label underneath; when the label differs from the position, the position follows in brackets.
- Cancel and Apply at the bottom.
| To do this | Do this |
|---|---|
| Select pages | Click a page; Shift-click for a range; Ctrl-click to add or remove one. Or press the mouse button in the gap beside a page and drag a rectangle over the pages you want; hold Ctrl or Shift to add to the selection. |
| Reorder | Drag a selected page. All selected pages move together. A vertical line marks where they will be inserted, and the grid scrolls when the pointer nears its top or bottom edge. |
| Reorder with the keyboard | Move the focus with the arrow keys, select with Space, then press Alt with an arrow key |
| Delete, rotate, duplicate | Use the toolbar, or press Delete, R (Shift+R for left) or Ctrl+D |
| Act on one page quickly | Hold the pointer over a page. Three small buttons appear in its corner: rotate, duplicate and delete. |
| Insert a file | Drag a PDF or image file from the desktop into the grid. It is inserted where the line shows. |
| Take pages from another document | Choose Open a second document. Its pages appear in a column on the right. Drag them into the grid, or select them and choose Insert selected pages. |
| Put pages into another document | With a second document open, drag the selected pages from the grid onto its column: they are copied into that file at the place you drop them, and with Shift held they are moved (removed from the open document, one undo step). Copy selected pages into this file does the same from the keyboard, at the end of the file. The column then shows the file as changed; Download this file saves it. Every change emits organizerSecondChange with the new bytes, the file name and the page count, so a host can store the file itself. Copying needs the permission to extract content from the open document. |
| Make thumbnails larger | Move the Thumbnail size slider |
| Undo a step | Ctrl+Z, or Undo in the toolbar |
Apply closes the organizer and keeps the changes. Cancel takes back everything done since the organizer was opened and closes it. Escape and the × in the corner close it and keep the changes, like Apply; they stay in the undo history.
Merge files#
- Choose Merge files… in the Pages tab, or press
Alt+Shift+M. - Choose Add files… and pick PDF and image files, or drop them on the dialog. A protected PDF asks for its password before it is added.
- Each file is a row with its name, its page count, a page range box and three buttons: move up, move down and remove. Drag a row by its name to reorder, or press
Altwith the up or down arrow key while the focus is in the row. - Type a range such as
1-3, 8in a row to take only those pages. An empty box takes all pages. - Set the options: Add a bookmark for each file (named after the file), Keep the bookmarks of the files, and Keep form fields. A kept field whose name is already used is renamed.
- Under Result, choose Insert into this document and the page to insert after, or Create a new document.
- Choose Merge. A progress bar shows the file being read; Cancel stops the merge and nothing is changed.
Inserting is one undo step. A new document opens in a new tab when the viewer has tabs: true, and is downloaded as merged.pdf otherwise. filesMerge fires with the file names, the page count, result (inserted or new) and, for a new document, its bytes.
Split a document#
- Choose Split… in the Pages tab, or press
Alt+Shift+S. - Choose how to split under Split by: Page ranges, Every number of pages, Top-level bookmarks, Maximum file size or Blank pages.
- Fill in the value that appears for that choice.
- Tick Download as one zip file to get a single archive; otherwise each part is downloaded as its own file.
- Choose Split document.
The open document is not changed. Each part has a name built from the file name, such as handbook-pages-1-3.pdf or handbook-2-Installation.pdf. Splitting at blank pages treats every page without content as a separator and leaves it out.
Resize to a paper size#
- Select the pages and choose Resize….
- Pick a Paper size (A4, A3, Letter, Legal) or type a width and height in points.
- Leave Scale the page content to the new size ticked to scale the content, annotations and form fields with the page. Scaling then offers Fit inside the page (everything stays visible) and Fill the page (the page is covered and the overflow is cut off), and Margin (pt) keeps a border free.
- Untick it to keep the content at its size and place it with Content position.
Page numbers#
- Choose Page numbers….
- Pick the Format:
1,Page 1,Page 1 of Nor1 / N. - Pick the Position: bottom or top, and left, center or right.
- Set the First number, the Font size and, if not all pages should be numbered, a Page range.
- Choose Add numbers.
Numbers added here are marked in the file. Remove existing numbers in the same dialog, or Remove page numbers under More, finds and removes exactly those, also after the file was saved and opened again. Page numbers that another program printed on the pages are not touched. Adding numbers to a page that already has some replaces them.
More commands#
| Command | What it does |
|---|---|
| Page labels… | Edits the labels that readers show instead of the position: the first page of a range, the numbering style, a prefix and the first number |
| Page boxes… | Edits the media, crop, bleed, trim and art box with a preview |
| Delete blank pages | Removes every page that has no content, no annotation and no form field. A scanned sheet that is an all-white picture is not recognised as blank. |
| Interleave with a file… | For double-sided documents scanned as two stacks. The pages of the chosen file are placed after each page of this document; tick The second file is in reverse order when the back sides were scanned last to first. |
| Multiple pages per sheet… | Downloads a new file with 2 or 4 pages on each sheet, or a Booklet whose sheets can be printed double-sided and folded. Links, form fields and bookmarks are not carried over. |
| Compress and download… | Runs the optimizer before the download; see Saving |
Blank scans and sideways pages#
Delete blank pages also finds scanned pages that are blank: a page that draws nothing but images counts as blank when, with 3% of each edge left out, at most 0.2% of the pixels of every image are darker than paper. findBlankPages(pages, { whiteLevel, tolerance, border, analyzeImages }) changes these numbers, or switches the image check off with analyzeImages: false. Images that are stored as JPEG or without compression are examined; a page whose image is stored as JPEG 2000, JBIG2 or CCITT fax is never reported as blank. Pages with an annotation or a form field are kept.
Rotate pages to match their text (pagesAutoRotate) looks at the direction of the text of every page, also the invisible text that text recognition added to a scan, and rotates the pages whose text does not read left to right. A page needs at least 20 letters, 60% of them in one direction; other pages are left alone. detectTextRotation(pageIndex) returns the rotation a page should have, and autoRotatePages(pages?) rotates and returns the pages it changed, as one undo step.
From code#
The viewer has the same operations as methods. Page indexes are zero-based and refer to the current order.
import { createPdfViewer } from '@birchui/pdf';
declare const container: HTMLElement;
declare const bytes: Uint8Array;
declare const scan: Uint8Array;
declare const appendix: Uint8Array;
declare const backSides: Uint8Array;
const viewer = createPdfViewer(container, { document: bytes, fileName: 'handbook.pdf', toolGroup: 'pages' });
await viewer.ready;
viewer.movePages([4, 5], 0);
viewer.rotatePages([1, 2], 90);
viewer.deletePages([7]);
viewer.reversePages([0, 1, 2]);
viewer.insertBlankPage(3, { width: 595, height: 842 });
await viewer.duplicatePages([0]);
await viewer.insertImagePages([scan], 1, { pageSize: 'a4', margin: 36 });
await viewer.insertPagesFrom(appendix, [0, 2], viewer.getPageCount());
await viewer.replacePages([1], appendix, [0]);
await viewer.interleaveDocument(backSides, { reverseSecond: true });
const merged = await viewer.mergeFiles(
[
{ data: appendix, name: 'Appendix A.pdf', pages: '1-3' },
{ data: scan, name: 'Signed order.png' },
],
{ at: viewer.getPageCount(), bookmarkPerFile: true, keepFormFields: false },
);
console.info(merged.pageCount);
const removed = await viewer.extractPages([0], { deleteExtracted: true });
console.info(removed.length, viewer.deleteBlankPages());
await viewer.resizePages([0], { width: 595.28, height: 841.89, scaleContent: true, fit: 'fit', margin: 18 });
await viewer.addPageNumbers({ format: 'Page {page} of {pages}', position: 'bottom-right', startNumber: 1 });
await viewer.removePageNumbers([0]);
const booklet = await viewer.imposePages({ layout: 'booklet' });
console.info(booklet.length);
viewer.on('pagesSplit', ({ parts }) => console.info(parts.map((part) => part.name)));
const parts = await viewer.splitDocument({ every: 10 });
console.info(parts.length);
viewer.openPageOrganizer();
viewer.runCommand('pagesMerge');| Method | Result |
|---|---|
movePage(from, to), movePages(indices, target) |
Moves pages. movePages moves them together so that they start at target, counted in the order before the move. |
rotatePages(indices, degrees?), deletePages(indices), reversePages(indices?) |
Rotate, delete, reverse |
insertBlankPage(at, size?) |
Inserts a blank page and returns its index |
duplicatePages(indices) |
Inserts copies after the last listed page; resolves with the number of pages added |
mergeDocument(source, at?), insertPagesFrom(source, pageIndexes, at?) |
Adds all pages, or the listed pages, of another PDF with their annotations and fields |
insertImagePages(images, at?, { pageSize?, margin?, fit?, dpi? }) |
One page per PNG or JPEG image |
replacePages(indices, source, sourceIndices?) |
Puts the listed pages of source (all when omitted) in the place of indices, as one undo step; resolves with the number of pages inserted |
interleaveDocument(source, { reverseSecond? }) |
Alternates the pages of the document with those of source |
mergeFiles(inputs, options?) |
Inserts several PDF or image files. Each input is { data, name?, pages?, password? }; options are at, bookmarkPerFile, keepBookmarks, keepFormFields, signal and onProgress. Resolves with { at, pageCount, documentIndexes, renamedFields }. |
extractPages(indices, { deleteExtracted? }) |
The pages as a new file; with deleteExtracted they are also removed |
findBlankPages(pages?), deleteBlankPages(pages?) |
The indexes of pages without content; deleting returns the removed indexes and always keeps one page |
resizePages(indices, { width, height, scaleContent, fit?, margin?, anchor? }) |
fit is 'fit' or 'fill'; without scaleContent the content keeps its size and anchor places it |
addPageNumbers({ format?, position?, startNumber?, pages?, fontSize?, color?, margin? }) |
format takes {page} and {pages}; resolves with the number of pages numbered |
removePageNumbers(pages?) |
Removes the numbers added by addPageNumbers; resolves with the number of pages changed |
imposePages({ layout, columns?, rows?, sheetSize?, margin?, gutter?, rightToLeft? }) |
A new file with several pages per sheet; layout is 'n-up' or 'booklet' |
getPageBoxes(index), setPageBoxes(indices, boxes) |
Reads and sets the media, crop, bleed, trim and art box |
splitDocument(options) |
The parts of splitPdf for the document as it is now; emits pagesSplit |
openPageOrganizer(), closePageOrganizer(), openMergeDialog() |
Opens and closes the dialogs |
runCommand(id) |
Runs a page command by name: pagesOrganize, pagesMerge, pagesInsertBlank, pagesInsertPdf, pagesInsertImages, pagesInsertClipboard, pagesDelete, pagesRotateLeft, pagesRotateRight, pagesDuplicate, pagesExtract, pagesSplit, pagesReplace, pagesMove, pagesReverse, pagesCrop, pagesResize, pagesNumbers, pagesRemoveNumbers, pagesLabels, pagesBoxes, pagesDeleteBlank, pagesInterleave, pagesImpose, pagesOptimize |
The methods do not show the signed-document warning; that is part of the buttons and menus. getPages() returns each page's width, height, rotation, its visible box and whether it is original, merged or blank.
Without a viewer#
The headless PdfDocument of @birchui/pdf/engine has the same methods; most of the ones that are asynchronous in the viewer because they wait for the display are synchronous here (mergeFiles, extractPages and impose stay asynchronous). The engine also exports functions that work on bytes.
import { createZip, imposePdf, mergePdfs, openPdfDocument, optimizePdf, splitPdf, zipSplitParts } from '@birchui/pdf/engine';
declare const contract: Uint8Array;
declare const annex: Uint8Array;
declare const photo: Uint8Array;
declare const fronts: Uint8Array;
declare const backs: Uint8Array;
const combined = await mergePdfs(
[
{ data: contract, name: 'Contract.pdf' },
{ data: annex, name: 'Annex.pdf', pages: '2-' },
{ data: photo, name: 'Site photo.jpg' },
],
{ bookmarkPerFile: true, keepBookmarks: true, onProgress: ({ done, total }) => console.info(done, total) },
);
const pdf = openPdfDocument(fronts);
pdf.interleaveDocument(backs, { reverseSecond: true });
pdf.deleteBlankPages();
pdf.replacePages([0], contract, [0]);
pdf.addPageNumbers({ format: '{page} / {pages}', position: 'bottom-center' });
const { bytes: scanned } = await pdf.save();
const chapters = await splitPdf(combined, { byBookmark: { level: 1 } }, { baseName: 'contract' });
const batches = await splitPdf(scanned, { byBlankPages: true }, { baseName: 'batch' });
const archive = zipSplitParts([...chapters, ...batches]);
const custom = createZip([{ name: 'combined.pdf', bytes: combined }]);
const handout = await imposePdf(combined, { layout: 'n-up', columns: 2, rows: 2, margin: 18, gutter: 9 });
const small = await optimizePdf(handout, { recompress: true });
console.info(archive.length, custom.length, small.bytes.length);| Function | Result |
|---|---|
mergePdfs(inputs, options?) |
One new document from several PDF and image files. Same inputs and options as mergeFiles, without at. |
splitPdf(bytes, options, { baseName? }) |
One named file per part |
zipSplitParts(parts), createZip(entries) |
A zip archive (stored, no compression, since PDF data is already compressed). Entry names are made unique and stripped of folders that point outside the archive. |
imposePdf(bytes, options) |
A new document with several pages per sheet, or a booklet |
bookletOrder(pageCount, rightToLeft?) |
The page index pairs of each booklet sheet side, -1 for an empty place |
Split options#
| Option | Parts |
|---|---|
ranges |
One part per [first, last] pair of zero-based page indexes, both included, or a string of one-based ranges such as '1-3,4-9,10-' |
every |
Consecutive parts of that many pages |
byBookmark |
A new part at every bookmark down to level (default 1); the part's title is the bookmark title. Pages before the first bookmark form a part of their own. |
maxBytes |
As many pages per part as fit under the size, measured on the real output. A single page that is larger than the limit still becomes a part. |
byBlankPages |
A new part after every blank page; the blank pages are left out |
parsePageRanges(text, pageCount) turns a range string into index pairs and selectPages(pageCount, 'odd' | 'even' | 'all' | ranges) returns page indexes; both throw a RangeError for a range outside the document.
Cropping#
Crop pages asks how much to trim from each edge, in points, and whether to apply it to all pages. Remove crop restores the full page. From code, cropPages takes the new visible rectangle in PDF user space, or null to remove the crop:
import { openPdfDocument } from '@birchui/pdf/engine';
const pdf = openPdfDocument(scanBytes);
const [first] = pdf.getPages();
const [x1, y1, x2, y2] = first.box;
pdf.cropPages([0], [x1 + 36, y1 + 36, x2 - 36, y2 - 54]);
pdf.cropPages([1], null);Cropping sets the page's /CropBox. The content outside it is hidden, not removed; use redaction to remove content. In the viewer, cropping is one step in the undo history, like the other page tools, and viewer.cropPages(indices, box) does the same from code. See Document tools.
What moves with a page#
- Annotations, links and form widgets follow their page when it moves, and are removed with it when it is deleted.
- Bookmarks keep pointing at the right page after a reorder. Bookmarks to deleted pages remain in the outline without a target.
- Annotations and form fields of a merged document are imported and stay editable. A merged field whose name is already taken is renamed.
- Every page operation is one undo step that also restores the annotations and form fields it touched.
pagesChange fires with the new page list and a reason: move, rotate, delete, insert, merge, redaction, crop, content or history.
Saving after page changes#
Rotations alone still save as an incremental update. Reordering, deleting, inserting and merging write a compact full rewrite that copies only the objects still in use, so deleted pages are really gone from the file. Extracting pages never changes the open document unless you ask for the pages to be deleted.
Viewing rotation#
The rotate commands of the view menu and rotateView() turn the whole view without changing the document. Rotating pages with the page tools changes their /Rotate entry in the saved file.
Not included#
- Rotating scanned pages automatically by the direction of their text.
- Recognising a scanned all-white sheet as blank; only pages without content are found.
- Compressed entries in the zip archive; files are stored as they are.