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 Go.
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
doc, err := nexpdf.Open("report.pdf")
if err != nil {
log.Fatal(err)
}
defer doc.Close()
docx, _ := doc.ToDOCX()
os.WriteFile("report.docx", docx, 0o644)
xlsx, _ := doc.ToXLSX() // one sheet per page, tables rebuilt
os.WriteFile("report.xlsx", xlsx, 0o644)
pptx, _ := doc.ToPPTX() // one slide per page
os.WriteFile("report.pptx", pptx, 0o644)PDF to text formats
| Method | Output |
|---|---|
ToHTML() | HTML |
ToReflowHTML(optionsJson) | Responsive HTML for small screens |
ToJSON() | The document content as JSON |
ToXML() | The document content as XML |
ToCSV() | The tables as CSV |
ToRTF() | RTF |
ExtractMarkdown() | Markdown (no module needed) |
html, err := doc.ToReflowHTML(`{"images":true,"title":"Report"}`)Office, HTML and e-books to PDF
docx, _ := os.ReadFile("proposal.docx")
pdf, err := nexpdf.OpenOffice(docx) // Word, Excel or PowerPoint, format detected
if err != nil {
log.Fatal(err)
}
defer pdf.Close()
pdf.Save("proposal.pdf", false)
invoice, err := nexpdf.FromHTML("<h1>Invoice 1042</h1><p>Total: 120 EUR</p>")
if err != nil {
log.Fatal(err)
}
defer invoice.Close()
invoice.Save("invoice.pdf", false)
epub, _ := os.ReadFile("book.epub")
book, err := nexpdf.OpenEbook(epub) // EPUB, FictionBook, XPS/OpenXPS, CBZnexpdf.Open and nexpdf.OpenBytes also convert Word, Excel and PowerPoint files directly.
Word options
nexpdf.OpenDOCXWithOptionsJSON(data, optionsJSON) opens a Word file with
{"show_comments":false,"show_revisions":false} ("" = defaults):
docx, _ := os.ReadFile("review.docx")
pdf, err := nexpdf.OpenDOCXWithOptionsJSON(docx, `{"show_comments":true,"show_revisions":true}`)
if err != nil {
log.Fatal(err)
}
defer pdf.Close()
pdf.Save("review-markup.pdf", false)Comments are always exported as PDF text annotations anchored at the commented text, with their
replies and resolved state. show_comments also draws them in balloons in a markup area at the
right of each page (the page content scaled down, as Word prints with markup). show_revisions
shows tracked changes as markup (coloured underlined insertions, struck deletions, change bars)
instead of the final document, which is the default.
Word conversion also lays out section columns (equal or unequal, separators, column and continuous
breaks), conditional table styles (tblStylePr with tblLook and banding), tight and through
wrapping along wrap polygons, floats 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 including the *IFS
family, lookup including XLOOKUP, INDEX, OFFSET and INDIRECT, text including TEXT format
codes, dates and times, logic, finance, information, FILTER, SORT, UNIQUE, SEQUENCE), LET
and 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 (calcPr iterate, count and delta). Conditional formatting
draws every built-in and x14 icon set and x14 data bars (negative colours, axis, direction,
gradient, border).
nexpdf.OpenXLSXWithClock(data, clockUnixSeconds) makes NOW() and TODAY() return a fixed
time (no time zone applied), for reproducible output:
xlsx, _ := os.ReadFile("report.xlsx")
pdf, err := nexpdf.OpenXLSXWithClock(xlsx, 1798502400) // 2026-12-29 00:00:00Right-to-left and complex scripts
Word, Excel, PowerPoint and HTML conversion shape text with OpenType (Arabic joining, Indic
reordering, marks, ligatures) and order it with the full Unicode bidi algorithm: w:bidi and
w:rtl in Word, right-to-left sheets and readingOrder in Excel, right-to-left paragraphs in
PowerPoint, and dir and direction in HTML.
Images to PDF
tiff, _ := os.ReadFile("scan.tiff")
pdf, err := nexpdf.OpenImage(tiff) // one page per picture (multi-page TIFF too)
if err != nil {
log.Fatal(err)
}
defer pdf.Close()
photo, _ := os.ReadFile("photo.jpg")
n, _ := pdf.PageCount()
pdf.InsertImagePages(int(n), photo) // append more pictures
pdf.Save("scans.pdf", false)Page images
To export pages as PNG, see Rendering.