A PDF file is a collection of pages with a cross-reference table that maps page numbers to byte offsets. Splitting extracts pages by creating a new file with only the selected page references. No re-encoding required.
How splitting works internally
A PDF file has a structure like this:
Header
Body (objects: pages, fonts, images, etc.)
Cross-reference table (maps object numbers to byte offsets)
Trailer (points to the root object and cross-reference table)
Splitting a PDF means:
- Reading the cross-reference table
- Identifying which objects belong to the desired pages
- Copying those objects to a new file
- Writing a new cross-reference table and trailer
- Handling shared resources (fonts, images used by multiple pages)
The "shared resources" part is the complication. If pages 1 and 5 share an embedded font, splitting out page 5 alone must include that font in the new file.
Common split patterns
Range extraction: Pages 1-5 from a 20-page document. Most common for extracting chapters or sections.
Every N pages: Split a 100-page document into 10-page chunks. Common for batch processing or meeting file size limits.
By bookmark: Split at PDF bookmark boundaries, producing one file per chapter or section.
Remove pages: Create a new PDF excluding specific pages. Effectively a split that removes rather than extracts.
Using pdf-lib in JavaScript
import { PDFDocument } from 'pdf-lib';
async function splitPdf(pdfBytes, startPage, endPage) {
const srcDoc = await PDFDocument.load(pdfBytes);
const newDoc = await PDFDocument.create();
const pageIndices = Array.from(
{ length: endPage - startPage + 1 },
(_, i) => startPage - 1 + i
);
const copiedPages = await newDoc.copyPages(srcDoc, pageIndices);
copiedPages.forEach(page => newDoc.addPage(page));
return await newDoc.save();
}
For splitting PDFs by page range or extracting specific pages, I built a splitter at zovo.one/free-tools/pdf-splitter. It processes the file in your browser and handles shared resources correctly.
I'm Michael Lip. I build free developer tools at zovo.one. 500+ tools, all private, all free.
Top comments (0)