Qu

pdf.add_attachment

Builtin index · File I/O

result = pdf.add_attachment(src, filename, bytes)

Input: src, filename, bytes · Output: result

What it is

Embeds a file under filename. bytes is a path or a Vec of bytes, the same dual form every other src argument here takes. Creates the /Names/EmbeddedFiles chain if the document does not have one yet. Adding the same filename twice keeps both — pdf.extract_attachment then reads back the first.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = pdf.add_attachment(src, filename, bytes)
src Vecbytes is a path or a Vec of bytes, the same dual form every other src argument here takes.
filename —Embeds a file under filename.
bytes Vecbytes is a path or a Vec of bytes, the same dual form every other src argument here takes.
result Vec
Returns a Vec of bytes.

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

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