pdfspine
API reference

Documents & pages

API for the Document and Page classes — opening a PDF and working with its individual pages.

A Document is a parsed PDF; obtain one with pdfspine.open. A Page is one page of a Document, obtained with doc[i] or doc.load_page(i).

Document

Full API for pdfspine.Document — methods, signatures, and docstrings — is generated from source. See the pdfspine API reference or your editor's autocomplete.

HTML export

doc.to_html() -> str
doc.save_html(path: str | os.PathLike[str]) -> None

to_html() combines each page's Page.get_text("html") fragment, in page order, into a complete HTML5 document with a UTF-8 declaration. The result can be opened directly in a browser. The title falls back from PDF metadata to the input filename and then PDF document, with special characters escaped.

save_html() writes that document as UTF-8 and follows the other save methods' None return convention. It accepts strings and path-like objects; filesystem errors are propagated.

This is distinct from Table.to_html(), which returns a single HTML <table> rather than a page or whole document.

Page

Full API for pdfspine.Page — methods, signatures, and docstrings — is generated from source. See the pdfspine API reference or your editor's autocomplete.

On this page