Extract PDF pages

Drop or upload your PDF file.

Enter page ranges, like "1" or "2-" or "1-3,0,4-2"
("0" means a new blank page)

Privacy: Your PDF file is not sent to any server; everything happens locally in your browser. To verify this, you can disconnect from the internet after loading this page, or even simply save this page (everything is self-contained in a single HTML file) and use it offline.


What's this?

Sometimes you may want to extract only a few pages from a PDF, or reorder pages, or insert new blank pages. This is easy enough to do on a "real" computer using some tool like pdftk or pdfjam (wrapping the pdfpages package for LaTeX) or mutool or many others, but it seems somewhat harder on phones. No matter: for many of us, every operating system these days seems to be used primarily to launch another cross-platform operating system: the web browser.

To use this tool, upload a PDF file above, enter a specification of what pages you want extracted, then click on "Done". Then you can click on the link to download a new PDF file with reordered pages.

Specification syntax

To get a single page, use the page number, e.g. for page 3 use "3".

A range of pages can be represented by using a hyphen (the ASCII stand-in for a dash), e.g. "2-4" means pages 2, 3, and 4. As a shortcut, one or both ends of the range can be omitted: "2-" means pages 2-n, and "-2" means pages "1-2". If in a range the latter number is smaller, then it means the pages in reverse order, e.g. "4-2" means pages 4, 3, and 2.

A blank page (that you want to insert into the PDF) may be specified by the digit "0".

A sequence of ranges can be specified using commas, e.g. "1-3,2-4" means pages 1, 2, 3, 2, 3, 4 (in that order).

Spaces are ignored.

(At least, everything above is what I intended, but the code may have bugs. Try it and let me know.)

Thanks

The code rearranges pages using pdf-lib (GitHub) (v1.3.0) by Andrew Dillon. I tried to use Mozilla's PDF.js, but its documentation on these “core” matters (as opposed to just rendering a PDF in a canvas or whatever) seems poor/nonexistent compared to pdf-lib, which is excellent.

This pages borrows heavily from something I made for a more specialized use-case: Möbius-printing helper.