Merged PDF Lost Its Title: The One-Line Fix, Run on Both Tools

A test deck titled Test Deck Orig, merged with itself through pypdf and PyMuPDF, came out with the title gone in both outputs: PyMuPDF's merged file returned an empty title field, and pypdf's returned nothing at all where the title should be. The fix is one line per tool, set on the writer before saving — the document metadata setter on the PyMuPDF object, and the writer metadata call on the pypdf writer — and in our runs both fixed files read back the exact string we set. If your pipeline routes merged PDFs into search indexing, a document system, or anything that sorts by title, this silent loss is why your filings come up blank. Everything below comes from a run executed today; quoted values are verbatim readbacks; no accuracy claims and no price tags anywhere.

Day 11 of our 28-day series, and a page dedicated to the finding from yesterday's run — the one detail in the split and merge comparison that came out of our own runs rather than a manual. Same rules as the rest of the series: tools we executed get their behavior described verbatim; what we did not run is listed with the reason.

The failure, observed from our runs

The recipe: a one-page deck titled Test Deck Orig with author pdf2mdtool test bench, merged with a copy of itself. Here is what reading the title back from each merged output returned, run by run:

Step in our runPyMuPDF readback (verbatim)pypdf readback (verbatim)What it means
Open the original single-page deckTest Deck OrigTest Deck OrigBoth libraries read the source title fine — the loss happens at write time, not read time
Merge deck with itself, save, reopen, read titleEmpty stringNone — the title entry was absent entirelyThe loss is real and slightly different per tool: one returns a blank, the other drops the key
Same merge, plus one line setting metadata on the writer, save, reopenMerged Deck (fixed)Merged Deck (fixed)Both fixed files carry the exact string that was set — the fix reads back clean

Why merges drop titles (what the run supports, stated plainly)

A merge rebuilds the page tree of a new document from the page objects of the sources. The title, author and creation date live in a separate structure — the document information dictionary — and a writer that inits a fresh document does not carry it over for you. Our run backs the practical consequence: the loss is silent, so nothing in the merge output warns you, and the only symptom shows up later when something else needs the title. That is the entire reason this page exists: we watched it happen twice with our own readbacks, and both losses became blanks in real saved files, not warnings on screen.

The one-line fix, per tool (from the same runs)

PyMuPDF: set the metadata on the document object before saving — one call, then save. In our run the saved file read back Merged Deck (fixed) exactly.

pypdf: call the writer's metadata setter with the title (and any other fields you rely on) before writing the file. Also one call; our saved file read back Merged Deck (fixed) the same way. Note the input format difference between the two libraries — one takes plain keys, the other takes slash-prefixed keys — which is the only reason you might reach for one over the other when patching an existing pipeline; both accept the same string and both read it back identically in our runs.

m2.set_metadata({"title": "Merged Deck (fixed)"})    # PyMuPDF — m2 is the merged document object, set before save

w.add_metadata({"/Title": "Merged Deck (fixed)"})    # pypdf — w is the PdfWriter, set before write

What we could NOT test — and refuse to guess

- Other metadata fields surviving a merge — not run. Reason: our test set a title and an author; how creation dates, keywords, producers or custom XMP fields behave in a merge was not measured, and we will not print guesses about them.

- Whether any configuration flag makes a writer inherit the source title automatically — not run. Reason: we did not go hunting through library options for a workaround once the one-line fix read back clean in both tools; if such a flag exists, it is unverified here.

- How PDF viewers and search indexers treat the empty-versus-missing title difference — not run. Reason: that is an outside-tool behavior question and our test bench covers the two Python libraries only.

Decision rule this run actually supports

- If a merged PDF feeds anything that reads titles (indexers, filing systems, listing pages): always set the title explicitly after the merge, in either library, and read it back from the saved file before routing the file onward. This run showed the loss in both tools, so the step applies regardless of which one you use.

- If you batch-merge hundreds of files: derive the new title from the sources on purpose (for example, join the two source titles) rather than hoping any writer preserves one.

- If titles do not matter in your workflow: nothing to do; merges worked correctly on page content in all our runs both yesterday and today.

Quick FAQ

Is the title loss total or partial?

In our runs it was total: the merged outputs carried no usable title at all — one tool left an empty string, the other omitted the entry. There was no partial residue to salvage.

Does the fix need to come before or after saving?

Before writing the file, in both libraries — it is a property of the writer, not a post-processing step. Our runs set it in the same breath as the merge and both readbacks came back clean from reopened files.

Can I reproduce your runs?

Yes: make any PDF, set its title with one library, merge it with a copy using either library, save, reopen, and print the title field. Compare against the table above. If your sources carry bookmarks or forms, note our test deck had neither — that is what yesterday's not-run list is for.

This page closes the loop on the metadata finding from yesterday's split and merge run. Bookmark pdf2mdtool.com and follow along.