Qu

pdf.set_metadata

Builtin index · File I/O

result = pdf.set_metadata(src, [title=], [author=], [subject=], [keywords=], [creator=])

Input: src, title, author, subject, keywords, creator · Output: result

What it is

Writes into a PDF's /Info dictionary (creating it if the file has none), touching only the fields passed โ€” a keyword left out is left exactly as it was, never cleared. At least one keyword is required. An empty string (title="") is a real written value, but reads back as none from pdf.info regardless, because pdf.info already treats an empty /Info string the same as an absent key; use pdf.strip_metadata to actually remove a field's presence.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = pdf.set_metadata(src, [title=], [author=], [subject=], [keywords=], [creator=])
src —not documented yet
title string, optionalAn empty string (title="") is a real written value, but reads back as none from pdf.info regardless, because pdf.info already treats an empty /Info string the same as an absent key.
author optionalnot documented yet
subject optionalnot documented yet
keywords optionalnot documented yet
creator optionalnot documented yet
result Vec
Returns a Vec of bytes, the new PDF โ€” same destination convention as pdf.merge.

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

# Only `subject` changes; title/author/producer/... are untouched.

tagged = pdf.set_metadata("paper.pdf", subject = "Impedance spectroscopy")
pdf.write_merge("tagged.pdf", [tagged])  # or write it out any other way


hits = pdf.find_text("paper.pdf", "impedance", case_sensitive = false)
for h in hits
    print("page {h.page}, offset {h.offset}")
end

d = pdf.text_diff("draft_v1.pdf", "draft_v2.pdf")
print("{length(d.differing_pages)} of {d.pages_b} pages changed")

s = pdf.structural_diff("draft_v1.pdf", "draft_v2.pdf")
if s.pages_a != s.pages_b
    print("page count changed: {s.pages_a} -> {s.pages_b}")
end

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

How it works

ยง metadata write / text search / diff (2026-09-25): appended as standalone arms rather than interleaved among the functions above -- two sibling lanes are touching this same match for page-geometry and bookmark/annotation work at the same time, and an addition at the end is the smallest possible diff against both of them.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.