Bookmarks Gone After Merging PDFs? Set Retention Rules

When merging, first decide whether to import the original table of contents. If you wish to create the top-level entry yourself, explicitly set import\outline=F

Merging PDFs with pypdf can quietly break your bookmarks. The merged file may open with an empty navigation pane, or clicking a bookmark may jump to the wrong page. This guide is for anyone who combines PDFs in Python and needs the table of contents to survive the merge.

You'll learn why these problems happen, how to decide whether to import the original table of contents, and how to check a merged file before you rely on it. The examples use synthetic samples, so run them on copies and keep your originals.

That does not guarantee they will work with every real file or product. Before you process important files, keep the original copies and verify your results against the boundaries and acceptance criteria described below.

Why do bookmarks disappear after merging PDFs? The short answer

Bookmarks break when the source files' bookmarks point to page numbers or objects from the original documents, so you must decide whether to import the original table of contents and check the result.

Your situationWhat to doWhy
You want to keep the source bookmarksDecide first whether to import the original table of contentsImported outlines can then be checked against the merged page order
You want to build the top-level entry yourselfExplicitly set import_outline=FalseThis avoids mixing the default import with your manual structure
Source files use Named Destinations with the same namesCheck for duplicate names before appendingA later file overwrites earlier definitions, which breaks links
You append the same reader more than onceCall reset_translation before each insertionOtherwise the second insertion reuses a reference copy of the first
The output file opens without errorsCompare page counts and table-of-contents offsets with the inputsSuccessful code execution does not guarantee a usable deliverable

Why merged bookmarks break

The direct cause

After you concatenate several PDFs with PdfWriter.append(), the output can show an empty left-hand navigation pane, or bookmarks can jump to the wrong page. This is a common problem in pypdf merges. The merge step itself is usually not the cause. The problem lies in the source files' bookmarks (Outlines), which reference the original page numbers or internal object references.

When you merge documents into a new file, the physical page numbers shift. The old bookmark tree does not update these offsets automatically.

The Named Destinations trap

A subtler case happens when source files use Named Destinations instead of absolute page numbers. If two source files define the same named destination, the file appended later overwrites the earlier definition, and the links break.

A self-contained synthetic example

The dependencies are listed in the import section of the code. The code builds its inputs in memory.

from io import BytesIO
from pypdf import PdfReader, PdfWriter
def source(pages):
    writer = PdfWriter()
    for _ in range(pages):
        writer.add_blank_page(width=200, height=200)
    out = BytesIO()
    writer.write(out)
    return out.getvalue()
writer = PdfWriter()
for title, raw in [("Part A", source(2)), ("Part B", source(1))]:
    start = len(writer.pages)
    writer.append(PdfReader(BytesIO(raw)), import_outline=False)
    writer.add_outline_item(title, start)
out = BytesIO()
writer.write(out)
reader = PdfReader(BytesIO(out.getvalue()))
assert len(reader.pages) == 3
assert len(reader.outline) == 2
assert reader.get_destination_page_number(reader.outline[0]) == 0
assert reader.get_destination_page_number(reader.outline[1]) == 2

Define the input boundaries and expected output

To test merging logic reliably, build controlled synthetic samples rather than relying on real production files, which vary widely in structure. Suppose you have two source files for testing.

What a silent failure looks like

If you append the two files without any preprocessing, you may find that:

  • Only one user_name field is editable, while the other is obscured or its data is lost.
  • All bookmarks point to page ranges in source_a, or clicking the bookmark for source_b produces an error.

This kind of silent failure can be more dangerous than a crash. The document loses usability, and no exception tells you so.

Decide whether to import the original table of contents

Start by deciding whether the merged file should import the original table of contents. If you want to create the top-level entry yourself, explicitly set import_outline=False. This avoids mixing the default import with your manual reconstruction.

This guide demonstrates page numbers and table-of-contents offsets only. It does not handle form-field isolation.

Check the merged result

Successful code execution does not mean the file is usable. Use the table below to decide what to check automatically and what needs a manual review.

ObservationWhat to doWhat not to infer
Total merged pagesAdd up the pages of each input and verify the total against itDo not assume delivery is fine when the numbers differ
Second table of contentsCheck its starting offsetDo not assume it still points to the first page
Source directory retention policyImport explicitlyDo not assume this avoids duplicate table-of-contents entries

Watch for repeated insertions

Call reset_translation whenever you append the same reader object repeatedly. If you insert different pages of the same PDF into the output several times, call this method before each insertion. Otherwise, the second insertion uses a reference copy of the first, and changing one changes the other.

This is a code-level detail, but during end-to-end checks it shows up as "editing one piece of content unexpectedly changes another." That symptom is easy to mistake for a software bug.

Use this checklist for document translation

File splitting, encryption, and attachment handling are part of delivery preparation. Translation cannot replace these checks. Keep the original documents and your processing checklist, then review the translated manuscript's page order, hyperlinks, and content integrity.

OmniDoc translates PDF, Word, PowerPoint and Excel files: scanned pages are recognized first, table cells are translated one by one so tables keep their rows and columns, and a PDF comes back as both a bilingual and a translation-only file. Paid translation adds a glossary and context translation. If your team wants to start from real files, it is worth evaluating with your own samples.

References and next steps

❓ FAQ

1. Why does my merged PDF have an empty bookmark pane?

Source bookmarks usually reference the original page numbers or object references. When you merge files, those page numbers shift, and the old bookmark tree does not update automatically.

2. What should I set to avoid mixing imported and manual bookmarks?

Decide whether to import the original table of contents. If you want to build the top-level entry yourself, explicitly set import_outline=False.

3. Why do links break when several source files share named destinations?

A later file with the same named destination overwrites the earlier definition. Check for duplicate names before you append.

4. Why does editing one part of the output change another part?

You probably appended the same reader more than once without calling reset_translation before each insertion. The second insertion then uses a reference copy of the first.

📝 Summary

Bookmarks break after a merge when source bookmarks point to the original page numbers or named destinations. Decide whether to import the original table of contents, check page counts and offsets against your inputs, and keep your original files. Verify each step with your own samples before you rely on the result.

Try it now: upload a document and get it translated with the layout intact

Updated 2026-11-29