PDF Bookmarks Editor
Operator: Abdulla Al Fahad. How tools are built and checked
Bookmarks are the clickable outline that appears in the side panel of a PDF viewer. A report exported from a word processor usually gets them from its headings, but plenty of PDFs arrive with none: scans from an office copier, files merged from several sources, or exports where the heading styles were never set. Others have bookmarks that are wrong, such as a chapter list that still points at the page numbers of an earlier draft, or a dozen entries all called "Untitled".
This editor opens the outline of one PDF as an ordinary list. Each row has a title and a page number, and buttons to move it, nest it under the row above, add a row after it or delete it. Two helpers cover the common bulk jobs: one bookmark for every page, and a pasted table of contents in a simple text format. When the list is right, the page writes a new outline into a copy of the PDF and offers it for download.
Key features
- Editable list of bookmarks with title, target page and nesting level
- Move up and down with everything nested underneath, nest under the row above, move out a level, add after, delete
- Undo for the last 50 changes, including deletions
- Literal find and replace across all titles, with an option to match upper and lower case
- One bookmark per page from a title pattern such as "Page {n}"
- Import from text lines like "Terms | 2", nesting by indentation, with every faulty line reported by number
- Reads explicit and named destinations, GoTo actions, and first and last page commands
- Options to open the bookmarks panel with the file, to save nested entries expanded or collapsed, and to choose where a bookmark lands
How the outline is stored, read and saved
In the file, the outline is a chain of dictionaries hanging off the document catalog under /Outlines. Each entry has a /Title, links to its parent and to the entries before and after it, links to its first and last child, a /Count of descendants, and a target. The target is normally a destination array naming a page object and a way of showing it, such as /Fit for the whole page or /XYZ with a left edge, a top edge and a zoom.
Targets are read in every form the format allows: a destination written out in full, a named destination looked up in the document's name tree or in the older /Dests dictionary, a GoTo action, and the viewer commands for the first and last page. A few writers store a page as a plain 0-based number instead of a page reference; that is accepted too, as viewers do. Each resolved target becomes a page number counted from 1 in file order.
On save, every title is written as a UTF-16 hexadecimal string, so accented letters, Cyrillic, Chinese or emoji survive in any viewer that follows the PDF specification. Bookmarks that kept their original page also keep their original position and zoom, unless you choose another landing style. The colour and the bold or italic style an entry had in the source file are copied across. The old outline entries are deleted from the file rather than left behind as unused objects.
How it works
A chosen file larger than 50 MB is turned away at once, and so is one whose opening kilobyte lacks the %PDF- marker that every PDF carries. The document is then parsed with pdf-lib; an encrypted file stops at this point. The outline is walked entry by entry, and the walk stops if an entry links back to one it has already visited, which damaged files sometimes do. Each entry's target is resolved to a page, or marked with the reason it cannot be.
Editing happens on a plain list in which every row has a level. Indenting a row adds one to its level and to the levels of everything nested under it. Moving a row out a level leaves it where it is on screen, so rows listed below it at its old level become its children and the list stays in page order. Moving up or down swaps a row, together with its children, past the neighbouring row at the same level.
Each save starts from the PDF exactly as you loaded it, not from a copy saved earlier, so saving twice never stacks one outline on top of another. Rows without a page are taken out first, and anything nested under them moves up one level. The remaining rows are built into a tree, new outline dictionaries are written with their /Count values worked out from the expanded setting, the catalog's /Outlines entry is pointed at the new root, and the old entries are deleted. The result is serialised to a fresh PDF, downloaded under the original name with -bookmarks before the extension.
Common use cases
- Adding a clickable chapter list to a scanned book or manual that came off a copier with no outline at all
- Bookmarking every page of a bundle of scanned receipts or delivery notes, so a reader can jump to page 37 from the side panel
- Rebuilding the outline of a PDF merged from five separate reports, where each part brought its own top-level entries
- Renaming bookmarks exported from heading styles, such as removing "Heading 2:" or a draft number from every title at once
- Nesting a flat list of 40 sections under four part headings so the outline opens as a short overview
- Removing every bookmark from a file before sending it, when the outline reveals internal section names
How to use this tool
- Load the PDF whose outline you want to change, by dropping it on the dashed box or clicking the box.
- Read the line under the drop zone: page count, how many bookmarks were found, and any warnings about entries that do not point to a page.
- Edit the list: change titles and page numbers, nest and reorder rows, or use the three helpers below it.
- Fix anything shown in red; the save button stays disabled until every title is filled in and every page is in range.
- Choose the save options, press Save PDF with these bookmarks and download the copy.
Example
lease-scan.pdf, 9 pages from a copier, no bookmarks; this text pasted into Import from text, then Replace the list
Lease summary | 1
Terms | 2
Rent and deposit | 3
Repairs | 5
Schedules | 7
Schedule A: inventory | 7
Schedule B: floor plan | 9lease-scan-bookmarks.pdf, saved with the bookmarks panel ticked and nested bookmarks expanded
Chips: 7 bookmarks · 2 levels · Opens with the bookmarks panel · Nested bookmarks expanded
Lease summary (p. 1)
Terms (p. 2)
Rent and deposit (p. 3)
Repairs (p. 5)
Schedules (p. 7)
Schedule A: inventory (p. 7)
Schedule B: floor plan (p. 9)
Each bookmark shows its whole page (/Fit), because none had an original position to keep.Tips for best results
- For a long contents list, type or paste it into Import from text rather than adding rows one by one. Two spaces at the start of a line nest it under the line above.
- Press Copy list into the box to turn the current outline into text, edit it in the box (or in any text editor), then replace the list with the edited version.
- Use find and replace to clean titles in one pass, such as replacing "Chapter " with "Ch. " across a hundred entries. Matching is literal, so punctuation needs no escaping.
- If the outline should open as a compact overview, untick Show nested bookmarks expanded. Readers then see only the top level until they open a part.
- Open the downloaded copy in your usual viewer and click a few bookmarks near the end of the document, where a wrong page number is most likely to hide.
Common pitfalls
Page numbers here are positions in the file, counted from 1. A book whose printed page 1 is the ninth page of the PDF needs 9, not 1, for its first chapter. When a PDF defines its own page labels, such as roman numerals for the front matter, you get a warning, but they are not used.
Entries that do not lead to a page of this file are left out when you save unless you give them one: web links, links into another PDF, scripts, named destinations the file does not define, and entries with no target at all. The page marks each of them in the list and names the dropped ones after saving.
Saving writes the whole file out again rather than appending to it, so a digital signature in the PDF is unlikely to validate in the copy. Viewers differ in how they show that: some mark the signature invalid, some say the document changed after signing, and some do not check. Add bookmarks before signing, not after.
Encrypted PDFs are refused, including files that open without a password but restrict printing or copying. Remove the protection first if you are allowed to, then load the unlocked copy.
Each original entry's open or closed state is not kept; the Show nested bookmarks expanded box sets the same state for all of them.
An outline can hold up to 5,000 bookmarks and 16 levels here. Deeper entries in a source file are moved up to level 16, and the number affected is reported.
Common errors and how to fix them
- Loading stops with a message that the PDF is encrypted.
- The file has a password or permission restrictions, and the editor does not decrypt files. Remove the protection with Unlock PDF, using the password if one is needed, and load the unlocked copy.
- A bookmark row says the original entry opens a web link, or points to a named destination the file does not define.
- Type the page the bookmark should open and it is saved as a normal page bookmark. Leave the page empty if you do not want it; it is then left out when you save.
- Import from text lists errors such as "Line 4: page 12 is outside this PDF".
- Nothing is imported until every line reads correctly. Fix the lines named in the list, usually a missing " | " before the page or a page beyond the last one, and press the import button again.
- The save button is disabled and a message asks you to fix the bookmarks first.
- A title is empty or a page number is missing or out of range. The message names the first such bookmark, and the row itself is outlined in red.
Best practices
- Keep bookmark titles short enough to read in a narrow side panel; put the detail in the document itself.
- Point each bookmark at the page where its section starts, and check the last few entries, where offsets from a cover page tend to show up.
- Keep the outline as shallow as the document allows, and add a level only where a part holds enough sections to need grouping.
- Keep the text version of a long outline in a note, so the same bookmarks can be pasted into a revised edition of the file.
The text format for importing an outline
Each line is one bookmark: the title, a vertical bar, then the page number, such as "Rent and deposit | 3". The page is read from after the last bar, so a title may contain a bar of its own. Blank lines are ignored.
Nesting comes from the start of the line. Each tab, and each pair of spaces, is one level deeper. A line indented two levels deeper than the line above is placed only one level deeper, because an outline entry cannot skip a level, and the count of adjusted lines is reported. The same format is produced by Copy list into the box, using two spaces per level.
Choosing where a bookmark lands
A destination says not only which page to open but how to show it. Whole page (/Fit) zooms so the full page fits the window, which suits scans and slides. Top of page at the current zoom (/XYZ) scrolls to the top edge of the page and leaves the reader's zoom alone, which suits text documents read at a comfortable size; for rotated pages the top edge is worked out from the rotation.
The default keeps whatever position and zoom each original bookmark had, as long as you did not change its page, and uses whole page for new or re-pointed bookmarks. Pick one of the other two styles to make every bookmark behave the same way, for example when a file's old bookmarks all jump to an awkward 400% zoom.
Frequently asked questions
Does the editor change the pages themselves?
No. Page content, fonts, images, links and form fields are copied unchanged. Only the outline and, if you tick the box, the page mode that asks viewers to show the bookmarks panel are changed.
Can bookmarks be made from the headings in the text?
Not automatically. The editor does not read the page text. Copy the contents page of the document into Import from text, add " | " and the page to each line, and import it.
Why does my viewer not open the bookmarks panel even though the box was ticked?
The box sets the PDF's page mode to UseOutlines, which is a request. Some viewers and browser PDF readers always start with their own layout and ignore it.
Can I copy the bookmarks of one PDF into another?
Yes, through the text box. Open the first PDF and press Copy list into the box. Then drop the second PDF on the page: the box keeps its text when another file is loaded, so you can press Replace the list straight away. Page numbers come across unchanged, so check them if the second file has pages added or removed; if a line points past its last page, nothing is imported and that line is named.