Conversion
Convert PDFs to Word, Excel, PowerPoint, HTML, JSON, XML, CSV and RTF, and create PDFs from Office files, HTML, e-books and images with NexPDF for Python.
License module
Conversion to and from Office, HTML, e-book and data formats needs the conversion module (Startup
tier and above). Images to PDF and Markdown export need no module.
PDF to Office
import nexpdf
with nexpdf.Document.open("report.pdf") as doc:
open("report.docx", "wb").write(doc.to_docx())
open("report.xlsx", "wb").write(doc.to_xlsx()) # one sheet per page, tables rebuilt
open("report.pptx", "wb").write(doc.to_pptx()) # one slide per pagePDF to text formats
| Method | Output |
|---|---|
to_html() | HTML |
to_reflow_html(options_json) | Responsive HTML for small screens |
to_json() | The document content as JSON |
to_xml() | The document content as XML |
to_csv() | The tables as CSV |
to_rtf() | RTF |
extract_markdown() | Markdown (no module needed) |
html = doc.to_reflow_html('{"images":true,"title":"Report"}')Office, HTML and e-books to PDF
with open("proposal.docx", "rb") as f:
pdf = nexpdf.open_office(f.read()) # Word, Excel or PowerPoint, format detected
pdf.save("proposal.pdf")
invoice = nexpdf.from_html("<h1>Invoice 1042</h1><p>Total: 120 EUR</p>")
invoice.save("invoice.pdf")
with open("book.epub", "rb") as f:
book = nexpdf.open_ebook(f.read()) # EPUB, FictionBook, XPS/OpenXPS, CBZDocument.open and Document.from_bytes also convert Word, Excel and PowerPoint files directly.
Text in Word, Excel, PowerPoint and HTML is shaped with OpenType (Arabic joining, Indic
reordering, marks, ligatures) and ordered with the full Unicode bidi algorithm: Word w:bidi and
w:rtl, Excel right-to-left sheets and readingOrder, PowerPoint right-to-left paragraphs, and
HTML dir and direction.
Word options
nexpdf.open_docx_with_options_json(data, options_json) converts a .docx with options
{"show_comments": false, "show_revisions": false}:
| Option | Default | Meaning |
|---|---|---|
show_comments | false | Draws comments in balloons in a markup area at the right of each page; the page content is scaled down, as Word prints with markup |
show_revisions | false | Shows tracked changes as markup (coloured underlined insertions, struck deletions, change bars) instead of the final document |
with open("draft.docx", "rb") as f:
pdf = nexpdf.open_docx_with_options_json(f.read(), '{"show_comments":true,"show_revisions":true}')
pdf.save("draft-markup.pdf")Comments are always exported as PDF text annotations anchored at the commented text, with replies
and resolved state, whatever show_comments says. The conversion also lays out section columns
(equal or unequal widths, separators, column and continuous breaks), conditional table styles
(first row, banding and the other tblStylePr parts selected by tblLook), tight and through
wrapping along wrap polygons, floating objects in table cells and text boxes, and tables in text
boxes.
Excel formulas
Formulas without a cached value are calculated; cached values still win. The calculation covers
references across sheets, defined names, shared and array formulas, dynamic arrays that spill
(#SPILL!), Excel error values and about 280 functions: maths, statistics (with the *IFS
family), lookup (XLOOKUP, INDEX, OFFSET, INDIRECT), text (with TEXT format codes), dates
and times, logic, finance, information, FILTER, SORT, UNIQUE, SEQUENCE, LET, LAMBDA
(named and recursive), MAP, REDUCE, SCAN, MAKEARRAY, BYROW, BYCOL and ISOMITTED.
Circular references show 0 as Excel does, or iterate as the workbook's iterative-calculation
settings say. Conditional formatting draws every built-in and x14 icon set and x14 data bars
(negative colours, axis, direction, gradient, border).
For reproducible output, nexpdf.open_xlsx_with_clock(data, clock_unix_seconds) makes NOW() and
TODAY() return a fixed time (seconds since 1970-01-01 00:00, no time zone applied):
with open("report.xlsx", "rb") as f:
pdf = nexpdf.open_xlsx_with_clock(f.read(), 1795910400) # 2026-11-29 00:00Images to PDF
with open("scan.tiff", "rb") as f:
pdf = nexpdf.open_image(f.read()) # one page per picture (multi-page TIFF too)
with open("photo.jpg", "rb") as f:
pdf.insert_image_pages(pdf.page_count(), f.read()) # append more pictures
pdf.save("scans.pdf")Page images
To export pages as PNG, see Rendering.