Edit, fill and protect PDFs in Python
Python functions that number pages, stamp watermarks, add signatures, fill and flatten forms, clean metadata, repair, encrypt and unlock PDFs.
Each writes a changed copy; the original is never modified.
| Function | What it does | Returns |
|---|---|---|
add_page_labels(path, output, pages=, text="{page} / {total}", position="bottom"|"top") | Page numbers, a footer or a header | Written |
add_watermark(path, text, output, pages=) | Stamp text such as DRAFT diagonally (up to 60 characters) | Written |
add_text(path, text, output, pages=, x=36, y=36, size=12) | Draw text such as a typed signature (points from the bottom-left corner) | Written |
fill_form(path, values, output, flatten=False) | Fill form fields by name (info lists them) | Written |
flatten(path, output) | Make form fields part of the page | Written |
remove_metadata(path, output) | Strip document properties | Written |
repair(path, output) | Rebuild a damaged PDF; fixed lists what was repaired | RepairResult |
protect(path, password, output) | Encrypt with AES-256 | Written |
unlock(path, output, password=) | Decrypt with a password you know; never guesses | Written |
Examples
import superpdf
superpdf.add_page_labels("report.pdf", "numbered.pdf", text="Page {page} of {total}")
superpdf.add_watermark("contract.pdf", "DRAFT", "draft.pdf")
superpdf.add_text(
"contract.pdf", "Signed: Ada Lovelace", "signed.pdf", pages="3", x=72, y=96
)
superpdf.fill_form(
"form.pdf", {"Name": "Ada Lovelace", "Agree": True}, "filled.pdf", flatten=True
)
superpdf.protect("payslip.pdf", "a long password", "locked.pdf")
superpdf.unlock("locked.pdf", "open.pdf", password="a long password")
print(superpdf.repair("damaged.pdf", "fixed.pdf")["fixed"])All functions are listed on All functions.