Convert PDFs in Python
Python functions that turn PDFs into Word, PowerPoint, EPUB, Excel or CSV, and images, Markdown or Office files into PDFs.
Each writes a new file and returns its path and size, plus what it found (pages, tables, slides or chapters).
| Function | What it does | Returns |
|---|---|---|
to_docx(path, output, pages=) | Editable Word: headings, bold and italic, lists, tables; OCR for scans | WordResult |
to_pptx(path, output, pages=) | PowerPoint, one slide per page, text as text boxes | SlidesResult |
to_epub(path, output, title=, author=, language="en", split="headings"|"pages") | EPUB 3 e-book in chapters | EpubResult |
extract_tables(path, output, pages=, format="xlsx"|"csv"|"json"|"markdown") | Tables and vector charts; output ends in the format’s extension | TablesResult |
from_images(inputs, output) | JPG or PNG images to PDF, one page each | Written |
from_markdown(path, output, page_size="A4"|"Letter", title=) | Typeset a Markdown file as a PDF | Written |
from_office(path, output) | Word, Excel, PowerPoint or OpenDocument to PDF (needs LibreOffice) | OfficeResult |
Examples
import superpdf
word = superpdf.to_docx("report.pdf", "report.docx")
print(word["tables"], "tables")
superpdf.extract_tables("report.pdf", "tables.xlsx") # one sheet per table
superpdf.extract_tables("report.pdf", "tables.csv", format="csv")
superpdf.to_pptx("slides.pdf", "slides.pptx")
superpdf.to_epub("book.pdf", "book.epub", author="Ada Lovelace")
superpdf.from_images(["page1.jpg", "page2.png"], "scan.pdf")
superpdf.from_markdown("notes.md", "notes.pdf", page_size="Letter")
superpdf.from_office("budget.xlsx", "budget.pdf") # needs LibreOfficeAll functions are listed on All functions.