Extracting Pages from a PDF: The Range Syntax That Catches Everyone
The very first version of Toolium's PDF Split tool had a bug that I am genuinely embarrassed about. A user wrote in to say that when they entered the range "1-3" expecting pages 1, 2, and 3, they got pages 0, 1, and 2 instead - everything was shifted by one. I had used zero-indexed page numbers in the UI without thinking about it, because that is how the underlying pdf-lib API works. To me, the first page is index 0. To everyone who has ever read a book, page 1 is page 1. The fix was a one-line change, but it taught me a useful lesson about the gap between what programmers find intuitive and what users actually expect.
That story is most of what I want to tell you about the PDF Split tool: it is mechanically simple, but the part that goes wrong is almost always the range syntax. Get the range right and the tool does what you expect. Get it wrong - even slightly - and you end up with the wrong pages or a confusing error. So this post is mostly about the syntax, the common ways people misuse it, and why the output file is sometimes a different size than you would predict.
The range syntax, with examples that go wrong
The tool accepts a comma-separated list of ranges and individual page numbers, one-indexed, where the first page of the document is 1. So:
1-5gives you pages 1, 2, 3, 4, and 5. Range is inclusive on both ends.3,7,12gives you exactly those three pages, in that order.1-3,8-10gives you pages 1, 2, 3, 8, 9, and 10 as a single output PDF.1-3,3-5gives you pages 1, 2, 3, 4, 5 - duplicates are deduplicated, and the final order follows the ascending page numbers, not the order in which you typed the ranges.
The most common ways I see people get this wrong:
- Using a hyphen between non-consecutive pages. Entering "3-12" when you meant "3 and 12" gets you ten pages instead of two. The hyphen always means "everything from X through Y."
- Forgetting that the syntax is one-indexed. If you are a programmer used to zero-indexed arrays, you might enter "0-4" expecting the first five pages. The tool will tell you that page 0 does not exist. Use "1-5."
- Entering pages beyond the document length. If your PDF has 20 pages and you enter "15-25," the tool extracts pages 15 through 20 and silently ignores 21-25. It does not throw an error, because there is no good policy for what to do; partial extraction seemed friendlier than refusing.
- Spaces. The parser allows them but does not require them. "1-3,5,8" and "1-3, 5, 8" and "1 - 3 , 5 , 8" all work. The spaces get stripped before parsing.
Why the extracted file is sometimes bigger than expected
This one surprises people who think of PDFs as a linear sequence of pages, like a stack of paper. The actual structure of a PDF is a tree of objects, and pages reference shared resources - fonts, embedded images, color profiles, sometimes JavaScript - through cross-references rather than embedding the resources directly. When pdf-lib extracts a set of pages, it has to also extract every resource those pages reference, because the new PDF has no way to "borrow" resources from the original.
This means that if you extract three pages from a 50-page document and those three pages happen to use an embedded font (which is common), the extracted PDF has to include the entire font even though most of its glyphs are not used by the three pages. The font might be 5 MB. Your three-page extract ends up larger than you would predict.
There is a workaround for this called font subsetting, where you regenerate the embedded font to include only the glyphs actually used. pdf-lib does not currently subset fonts during page extraction. Desktop tools like PDFsam Basic do; if you regularly extract small ranges from large documents and the output size matters, the desktop version is worth installing. For occasional use, the bloat is annoying but not usually a real problem.
The actual click-through
With the syntax out of the way, the rest of the tool is mechanical:
- Open the PDF Split tool.
- Drag your PDF onto the drop zone or click to browse for it. The tool reads the file in your browser, shows you the page count, and renders a preview of the first page so you can verify you uploaded the right document.
- Type your range in the input field. The placeholder shows the syntax. As you type, the tool highlights which pages will be included in the preview area.
- Click "Extract Pages." The tool produces a single output PDF containing only the pages you selected, in numeric order. Download starts automatically.
If you want each page as a separate file - say, you have a 10-page document and you want 10 individual files - that is currently a manual process: run the tool 10 times, once per page. I have heard the feature request for "split into N separate files" enough times that I will probably add it eventually, but the workflow above is fine for occasional use.
Privacy, briefly
Like every other Toolium tool, splitting happens entirely in your browser. pdf-lib reads your file from a JavaScript File object that the browser hands to the page; no network request carries the file's contents. If you are about to extract pages from a tax document, a contract, or a medical record, the contents do not leave your computer. The only network requests that occur during a split are analytics and ad-related, neither of which carry the file data.
When PDF Split is the wrong tool
A few situations where you should reach for something else:
- You need to OCR a scanned PDF before extracting. If your input is an image-only PDF (scanned from paper, no embedded text), the extracted pages will also be image-only. Toolium has no OCR step. Use Tesseract on the command line first, or use a tool like ABBYY FineReader.
- You want to reorder pages in addition to extracting. The tool extracts pages in their original numeric order. If you need page 5 followed by page 2 followed by page 8, you have to do two passes - extract first, then use PDF Merge to reorder the resulting one-page files.
- You need to remove specific pages (the inverse operation). Right now you have to list the pages you want, not the pages you do not want. If your document has 100 pages and you want everything except page 47, you have to type "1-46,48-100." This is annoying enough that I am considering adding an "exclude these pages" mode.
- The source is encrypted. Same as PDF Merge: encrypted PDFs are rejected up front rather than producing a corrupted output. Remove the password with a desktop tool first.
If a tool you wish existed is not here, tell me - dev@devtoolium.com. Most of what is on Toolium today was prompted by someone asking for it. The methodology I follow when picking what to build next is on the methodology page; the short version is that I build tools that solve a real annoyance I or someone I trust has actually hit.
Try the tool mentioned in this article
Open tool