Qu

pdf.merge

Builtin index · File I/O

result = pdf.merge(list)

Input: list · Output: result

What it is

Joins several PDFs into one, in list order, keeping every page. list is a List of sources (each a string path or a Vec of bytes); an empty list is an error. Bookmarks/outlines are dropped — a half-merged outline tree pointing at pages that moved is worse than none.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = pdf.merge(list)
list List, string, or Vecnot documented yet
result Vec
Returns a Vec of bytes, the new PDF.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

import pdf

i = pdf.info("paper.pdf")
print("{i.pages} pages, PDF {i.version}, produced by {i.producer}")

# Join two files, then take one page out of the result -- no disk in

# between, because every function also accepts bytes.

both = pdf.merge(["intro.pdf", "results.pdf"])
print(pdf.page_count(both))
pdf.write_pages("just_page_3.pdf", both, 3)

# A page range. `1 to 5` is already a Vec, so it just works.

pdf.write_pages("front.pdf", "paper.pdf", 1 to 5)

not run by the build — this one needs something the repository cannot supply · from file-io

import pdf

doc = pdf.merge(["intro.pdf", "results.pdf"])
doc = pdf.add_bookmark(doc, "Introduction", 1)
doc = pdf.add_bookmark(doc, "Results", 3)
rows = pdf.outlines(doc)
print(rows)  # index, level, parent_index, title, page_index


doc = pdf.add_annotation(doc, 1, type = "Text", rect = [10, 10, 200, 40], text = "draft")
doc = pdf.add_attachment(doc, "notes.txt", "notes.txt")
pdf.write_pages("with_extras.pdf", doc, 1 to pdf.page_count(doc))

not run by the build — this one needs something the repository cannot supply · from file-io