Qu

pdf.add_annotation

Builtin index · File I/O

result = pdf.add_annotation(src, page, type=, rect=, text=, [color=])

Input: src, page, type, rect, text, color · Output: result

What it is

Adds a simple annotation to a page (page counts from 1). type= (Str) is written verbatim as the PDF /Subtype — this does not validate it against PDF's own list. rect= is [x0, y0, x1, y1]. text= (optional Str) becomes the annotation's /Contents. color= (optional [r, g, b], each 0 to 1) sets the annotation colour (for "FreeText" it is the text colour, on a light-yellow callout box). The four text-markup types "Highlight", "Underline", "StrikeOut" and "Squiggly" are drawn from /QuadPoints, which Qu writes from rect= so they actually show (default colours yellow, green, red, red); a Highlight without them exists in the file but renders as nothing. "Text" (a note icon) and "Square" draw as written.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = pdf.add_annotation(src, page, type=, rect=, text=, [color=])
src —not documented yet
page —Adds a simple annotation to a page (page counts from 1).
type Strtype= (Str) is written verbatim as the PDF /Subtype — this does not validate it against PDF's own list.
rect —rect= is [x0, y0, x1, y1].
text Strtext= (optional Str) becomes the annotation's /Contents.
color optionalcolor= (optional [r, g, b], each 0 to 1) sets the annotation colour (for "FreeText" it is the text colour, on a light-yellow callout box).
result Vec
Returns a Vec of bytes: save with bytes_write(path, 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