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 Node.js.
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 { readFile, writeFile } from 'node:fs/promises';
import { PdfDocument } from '@nexdevit/nexpdf-node';
const doc = await PdfDocument.open('report.pdf');
await writeFile('report.docx', doc.toDocx());
await writeFile('report.xlsx', doc.toXlsx()); // one sheet per page, tables rebuilt
await writeFile('report.pptx', doc.toPptx()); // one slide per pagePDF to text formats
| Method | Output |
|---|---|
toHtml() | HTML |
toReflowHtml(options) | Responsive HTML for small screens |
doc.raw.toJson() | The document content as JSON |
doc.raw.toXml() | The document content as XML |
doc.raw.toCsv() | The tables as CSV |
doc.raw.toRtf() | RTF |
markdown() | Markdown (no module needed) |
const html = doc.toReflowHtml({ images: true, title: 'Report' });toReflowHtml takes pages, images, full_page and title.
Office, HTML and e-books to PDF
PdfDocument.open and PdfDocument.fromBytes convert Word, Excel and PowerPoint files, EPUB and
FictionBook books, XPS and OpenXPS files and CBZ comics directly (the format is detected):
const proposal = await PdfDocument.open('proposal.docx');
await proposal.save('proposal.pdf');
const invoice = PdfDocument.fromHtml('<h1>Invoice 1042</h1><p>Total: 120 EUR</p>');
await invoice.save('invoice.pdf');
// EPUB, FictionBook, XPS/OpenXPS, CBZ
const book = await PdfDocument.open('book.epub'); // or PdfDocument.fromEbook(source)
await book.save('book.pdf');Word comments and tracked changes
WasmDocument.openDocxWithOptionsJson(bytes, optionsJson) converts a .docx with options and
returns a raw document; wrap it with new PdfDocument(raw):
import { WasmDocument } from '@nexdevit/nexpdf-node';
const raw = WasmDocument.openDocxWithOptionsJson(await readFile('contract.docx'), '{"show_comments":true,"show_revisions":true}');
const reviewed = new PdfDocument(raw);
await reviewed.save('contract-markup.pdf');| Option | Default | Meaning |
|---|---|---|
show_comments | false | Draws the comments in balloons in a markup area at the right of each page, with the page content 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 |
Comments are always exported as PDF text annotations anchored at the commented text, with their
replies and resolved state. The Word converter also lays out section columns (equal or unequal,
with separators, column breaks and continuous section breaks), conditional table styles (with
tblLook and banding), 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): references across
sheets, defined names, shared and array formulas, dynamic arrays that spill (#SPILL!), Excel
error values and about 280 functions, among them the *IFS statistics, XLOOKUP, INDEX,
OFFSET, INDIRECT, TEXT format codes, dates and times, finance, FILTER, SORT, UNIQUE,
SEQUENCE, LET and LAMBDA (named and recursive) with 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 output that does not change from one run to the next, fix the time that NOW() and TODAY()
return (Unix seconds, no time zone applied):
const sheet = new PdfDocument(WasmDocument.openXlsxWithClock(await readFile('report.xlsx'), Date.UTC(2026, 10, 29) / 1000));
await sheet.save('report.pdf');Right-to-left and complex scripts
Word (w:bidi, w:rtl), Excel (right-to-left sheets, readingOrder), PowerPoint (right-to-left
paragraphs) and HTML (dir, direction) conversion shapes text with OpenType (Arabic joining,
Indic reordering, marks, ligatures) and orders it with the Unicode bidi algorithm.
To generate PDFs from Word, HTML or PDF templates and JSON data, see Templates.
Images to PDF
JPEG, PNG and TIFF pictures open as a PDF with one page per picture (multi-page TIFF too):
const scans = await PdfDocument.open('scan.tiff');
scans.raw.insertImagePages(scans.pageCount, await readFile('photo.jpg')); // append more pictures
await scans.save('scans.pdf');Page images
To export pages as PNG, see Rendering.