Merge PDFs
Join PDFs into one document, in the order of their file names.
POST https://api.pdfdispatch.com/v1/pdf/merge
Form fields
| Field | Type | Default | What it does |
|---|---|---|---|
files required | files | – | The PDFs to join, in the order of their file names (1-, 2-, … 10- sort as numbers). |
autoIndexBookmarks | boolean | false | Keep each file’s own bookmarks, moved to where its pages land in the result. |
titleBookmarks | boolean | false | Add one bookmark per file (its title, or its file name), with that file’s own bookmarks beneath it. |
bookmarks | JSON | – | Your own outline for the result (a list, as on Bookmarks), or a JSON object of file name to list, whose page numbers count within each file. |
flatten | boolean | false | Flatten form fields and annotations of the result. |
And all options on conversion routes, applied to the merged result.
Example
curl --fail-with-body \
--header "Authorization: Bearer $PDD_KEY" \
--form files=@1-cover.pdf \
--form files=@2-report.pdf \
--form files=@3-appendix.pdf \
--form titleBookmarks=true \
--output report.pdf \
https://api.pdfdispatch.com/v1/pdf/merge
In Python, with files whose names do not sort the way you want, number them as you upload them:
import os
import requests
parts = ["cover.pdf", "report.pdf", "appendix.pdf"]
files = [("files", (f"{i:02d}-{name}", open(name, "rb"), "application/pdf")) for i, name in enumerate(parts, 1)]
res = requests.post(
"https://api.pdfdispatch.com/v1/pdf/merge",
headers={"Authorization": f"Bearer {os.environ['PDD_KEY']}"},
files=files,
timeout=70,
)
res.raise_for_status()
open("report.pdf", "wb").write(res.content)
To merge Office documents, convert and merge in one step with merge=true on the Office route.