Automate PDF work in Python
Python functions that run several steps on a PDF, the same steps on many PDFs, or any superPDF tool by name.
Steps are dicts such as {"action": "rotate", "options": {"pages": "1", "angle": 90}}. The actions are extract, remove, rotate, crop (margin), scale (factor), flatten, labels, watermark and metadata-clear.
| Function | What it does | Returns |
|---|---|---|
run_pipeline(path, steps, output) | Up to 10 steps on one PDF, saved once | Written |
run_batch(inputs, steps, output_folder, suffix=) | The same steps on up to 50 PDFs; failures listed, not raised | BatchResult |
tools() | Every tool with its JSON input schema | list[dict] |
run_tool(name, arguments, allow=[…]) | Run any tool by name, with the folders it may use | the tool’s result |
Examples
import superpdf
steps = [
{"action": "extract", "options": {"pages": "1-3"}},
{"action": "watermark", "options": {"text": "DRAFT"}},
]
superpdf.run_pipeline("report.pdf", steps, "draft.pdf")
result = superpdf.run_batch(["q1.pdf", "q2.pdf"], steps, "drafts", suffix="draft")
print(result["failed"]) # [] when every file worked
print([tool["name"] for tool in superpdf.tools()])
superpdf.run_tool("pdf_info", {"input": "report.pdf"}, allow=["."])All functions are listed on All functions.