← All posts

Split a PDF into chapters using its own bookmarks

You have a 400-page manual, a standard, or a report, and you need it as one file per chapter. Twenty-four chapters. Which means looking up twenty-four starting page numbers, typing them into a splitter, and then renaming twenty-four files called document_1.pdf through document_24.pdf so anyone can tell which is which.

That is an hour of work, and it is an hour you almost certainly do not have to do. Open the document and look at the sidebar. If there is a list of chapters down the left, the file already contains the answer — the page each chapter starts on, and what it is called.

A splitter that reads that list does the whole job in one pass, and the parts come out named after the chapters instead of numbered.

Why the document already knows where the chapters are

The list in the sidebar is the document outline, and it is not printed on any page. It is a tree of entries hanging off the file's catalogue, and each entry holds two things: a title, and a destination — a reference to a page object plus how to position the view when you arrive.

That is the whole mechanism. The outline is a machine-readable table of "this heading, that page". Splitting at bookmarks means resolving each entry's destination to a page number, sorting them, and cutting between consecutive starts. Nothing is being detected or guessed. The work of deciding where chapters begin was done by whoever produced the file.

Two consequences worth holding on to. First, a contents page is not an outline. The contents page is ink, laid out like any other text; a tool reading it would be doing OCR-grade guesswork. If your file has a contents page but an empty sidebar, it has no outline and nothing to cut at.

Second, the outline is a tree, not a list. A chapter entry can have sections nested under it, and those can have sub-sections. So "split at the bookmarks" is incomplete as an instruction — you have to say how deep.

Splitting it

  1. Check the outline exists, and see how deep it goes. In Acrobat it is the bookmark ribbon on the left. In macOS Preview it is View, then Table of Contents. Chrome and Edge show a document outline button in their own sidebar. Expand a chapter: if arrows appear next to the top entries, your outline has more than one level.
  2. Count what you expect. Note how many top-level entries there are. You are going to compare that against the number of files you get back.
  3. Split at level 1. Put the file into Split PDF by bookmarks and leave the level at 1. Every top-level bookmark starts a new file.
  4. Take the extra file at the front. Anything before the first bookmark — cover, title page, contents — comes back as a file of its own, numbered rather than named, and the result tells you which page the first bookmark was on. That is one more file than you have chapters, and it is deliberate: a cover glued to the front of chapter one is worse.
  5. Check the boundaries on two files. Open the first and last chapter and confirm the last page of one is not the first page of the next.

What the files end up called

The bookmark's title becomes the filename, which means it has to survive a file system and a zip entry. The rules are worth knowing so you can predict the result rather than discover it:

One thing this does not fix: Chapter 10 sorts before Chapter 2 in every file manager, because it is sorting text. If that matters, the fix is at the source — number the bookmarks 01, 02 before you split, not the files afterwards.

When the file count does not match the chapter count

If the level is right and you still end up short, the pages are not lost — the chapter that seems to be missing is sitting at the end of the file above it, because its bookmark shared a page with the one before it, pointed at a destination that does not resolve, or was placed out of page order in the outline. All three are common, only one of them is reported in the result, and the full diagnosis, including which is which, is written up separately.

What this will not do

The parts have no outline of their own. Each one is a plain document containing its chapter's pages. The chapter's own sub-headings are not carried into it, because the pages are copied into a fresh document and the outline lives outside the pages. If you need the parts navigable, run each through Create PDF bookmarks afterwards.

It cannot invent an outline for a scan. A scanned book has no bookmarks and no headings to find one from — see below.

It splits at bookmarks and nothing else. If you want one file per page rather than per chapter, that is Split PDF by pages and its own short answer. If you want one chapter out of the middle and not the other twenty-three, Extract PDF pages is a page range and one file.

If there are no bookmarks

You get a refusal naming the level it looked at, which is useful: level 3 coming back empty on a two-level outline is a different problem from having no outline at all. Drop to level 1 first.

If the sidebar really is empty, build an outline and then split it — two steps, both quick. Create PDF bookmarks works from the size of the type on the page, or from a pattern such as Schedule \d+ that you type in; what it finds and where it gives up is set out in full elsewhere. Then split the result at level 1.

Two honest constraints on that route. The outline it builds is flat, one level, so level 1 is the only split available to you — which is what you want here anyway. And it replaces any outline the file already had rather than adding to it, so keep the original if the existing bookmarks are worth anything.

It also needs a real text layer, and a scan is a picture of words. Our PDF inspector tells you in a few seconds whether your file has text on every page, on some pages, or none, which is worth knowing before you spend time on a pattern that cannot match anything. Note that this deployment's OCR tool reports which pages need a text layer but does not add one, so a scan has to go through OCR elsewhere first.

From the command line, for a repeatable job

If this is a monthly task, do not do it in a browser.

PDFsam Basic is free and open source, runs on Windows, macOS and Linux, and has split-by-bookmarks as one of its modules, including a level setting and a filter on the bookmark text. For a recurring desktop job it is the better tool and we would rather you used it.

For a script, read the outline out and cut on the numbers:

The browser route wins when it is one document, today, and you do not want to install anything. The command line wins the second time you do it.