Skip to content

Python PDF functions

Every PDF function in the superpdf Python package (superPDF AI for Python), with its options and what it returns.

Import the package and call a function: import superpdf, then superpdf.merge(…). Results are typed dicts (TypedDict), so editors and type checkers know their fields; Written is {"output", "pages", "bytes"}.

Read and compare

FunctionWhat it doesReturns
export(path, format="markdown", pages=, tables=, ocr=True)Markdown, HTML or JSON text: headings, tables, charts as data, OCR for scansstr
export_json(path, …)The structure as a dict: title, pages with blocks, sectionsdict
export_pages(path, …)Markdown per page: [{"page": 1, "markdown": …}]list[dict]
info(path)Page count, page sizes and rotation, form fields, propertiesPdfInfo
list_files(folder=".")The PDFs in a folder, with sizes and datesFolder
read_text(path, pages=, max_chars=)The text layer, page by page (no OCR)Text
extract_structure(path, pages=, format=, max_chars=)Markdown, HTML or JSON plus the outline, capped at max_charsStructure
outline(path, format="markdown"|"json")The outline, with the pages each section coversOutline
compare(before, after, max_chars=20000)The words that changed, page by page, marked [-old-] and {+new+}Comparison

Read and compare: examples

Convert

FunctionWhat it doesReturns
to_docx(path, output, pages=)Editable Word: headings, bold and italic, lists, tables; OCR for scansWordResult
to_pptx(path, output, pages=)PowerPoint, one slide per page, text as text boxesSlidesResult
to_epub(path, output, title=, author=, language="en", split="headings"|"pages")EPUB 3 e-book in chaptersEpubResult
extract_tables(path, output, pages=, format="xlsx"|"csv"|"json"|"markdown")Tables and vector charts; output ends in the format’s extensionTablesResult
from_images(inputs, output)JPG or PNG images to PDF, one page eachWritten
from_markdown(path, output, page_size="A4"|"Letter", title=)Typeset a Markdown file as a PDFWritten
from_office(path, output)Word, Excel, PowerPoint or OpenDocument to PDF (needs LibreOffice)OfficeResult

Convert: examples

Pages

FunctionWhat it doesReturns
merge(inputs, output)Combine PDFs in orderWritten
split(path, output_folder, pages=, mode="ranges"|"pages")One PDF per range or per page; the folder is created if missingSplitResult
extract_pages(path, pages, output)Keep only some pagesWritten
remove_pages(path, pages, output)Drop pagesWritten
rotate_pages(path, output, pages=, angle=90|180|270)Rotate clockwiseWritten
resize_pages(path, output, mode="crop"|"scale", pages=, margin=24, factor=1)Crop a margin (points) from each edge, or scaleWritten

Pages: examples

Edit and protect

FunctionWhat it doesReturns
add_page_labels(path, output, pages=, text="{page} / {total}", position="bottom"|"top")Page numbers, a footer or a headerWritten
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 pageWritten
remove_metadata(path, output)Strip document propertiesWritten
repair(path, output)Rebuild a damaged PDF; fixed lists what was repairedRepairResult
protect(path, password, output)Encrypt with AES-256Written
unlock(path, output, password=)Decrypt with a password you know; never guessesWritten

Edit and protect: examples

Automate

FunctionWhat it doesReturns
run_pipeline(path, steps, output)Up to 10 steps on one PDF, saved onceWritten
run_batch(inputs, steps, output_folder, suffix=)The same steps on up to 50 PDFs; failures listed, not raisedBatchResult
tools()Every tool with its JSON input schemalist[dict]
run_tool(name, arguments, allow=[…])Run any tool by name, with the folders it may usethe tool’s result

Automate: examples

Arguments

  • Paths are strings or pathlib.Path; relative paths are relative to the current folder.
  • pages takes numbers and ranges such as "1, 3-5"; all pages when omitted.
  • Outputs must not exist yet; superPDF never overwrites a file. Folders for split and run_batch are created when missing.
  • Options you leave out take the tool’s default, shown above.
  • timeout (seconds) is accepted by the longer-running functions: 600 by default, 1800 for run_batch.

The same reference is in the package’s README on GitHub.