DOCX to PDF API
High-speed DOC/DOCX to PDF API with pixel-perfect accuracy. Enterprise security, advanced parameters, no MS Office required.
Sooner or later, every Node.js backend needs to change a file from one format to another. Maybe you need to turn a DOCX contract into a PDF, print a Markdown changelog, or make a JPG preview of a PDF page.
This guide covers the conversions Node developers search for most:
Each one comes with working code, and you can download the real input and output files at the end.
All examples use the official ConvertAPI Node.js SDK, so there is nothing to install besides one npm package. There is no LibreOffice to set up and no headless Chrome to manage. The same code runs on Windows, Linux, macOS, and serverless platforms like AWS Lambda.
npm install convertapi --saveconst convertapi = require('convertapi')(process.env.CONVERTAPI_TOKEN);
Get your API token from the dashboard and keep it in an environment variable.
Every conversion uses the same call shape: convertapi.convert(toFormat, parameters, fromFormat). The call returns a promise, so async/await works naturally.
There is no good pure-JavaScript way to convert Word documents. Packages like docx-pdf and libreoffice-convert are wrappers that need LibreOffice installed on your machine. LibreOffice also renders some things differently from Word, so headers, list numbering, and embedded fonts can shift. Puppeteer cannot open a DOCX file at all.
The API takes a different route and converts the document on the server. The output matches what Word itself produces, with headers, numbering, and fonts all in place:
const result = await convertapi.convert('pdf', {
File: './files/service-agreement.docx'
}, 'docx');
await result.saveFiles('./output/service-agreement.pdf');
The same call accepts doc files. To get a different output, just change the first argument. That is all it takes to switch between DOCX to PDF, DOCX to PNG, or DOCX to HTML.
The usual self-hosted answer is Puppeteer, which works but leaves you running and patching your own browsers. The HTML to PDF converter does that work for you and renders the page on the server, laid out for print:
const result = await convertapi.convert('pdf', {
File: './files/report.html',
RespectViewport: 'false'
}, 'html');
await result.saveFiles('./output/report.pdf');
You can convert a live web page too: use the web source format with a Url parameter instead of a file. Set RespectViewport to false so the page is laid out for print instead of a 1366px screen viewport.
You do not need to go through HTML first. MD to PDF is a direct conversion:
const result = await convertapi.convert('pdf', {
File: './files/release-notes.md'
}, 'md');
await result.saveFiles('./output/release-notes.pdf');
Headings, tables, code blocks, and horizontal rules all come out styled and ready to print. That makes it handy for changelogs, README exports, and generated reports.
Now for the reverse direction: rendering PDF pages as images for previews and thumbnails. Use PageRange to pick which pages you get:
const result = await convertapi.convert('jpg', {
File: './files/slide-deck.pdf',
PageRange: '1'
}, 'pdf');
await result.saveFiles('./output/slide-deck-page-1.jpg');
Each page becomes its own JPG file. The same pattern drives PDF to PNG and PDF to HTML when you need markup instead of pixels.
Developers keep needing the other direction too: turning a PDF back into an editable Office document. PDF to DOCX, PDF to XLSX, and PDF to PPTX all use the same one-liner, and only the target format changes:
const result = await convertapi.convert('docx', {
File: './files/service-agreement.pdf'
}, 'pdf');
await result.saveFiles('./output/service-agreement.docx');
Swap 'docx' for 'xlsx' to turn tables into a spreadsheet, or for 'pptx' to turn each page into an editable slide.
Which target fits which kind of PDF? As a rule of thumb:
Our PDF to Word, Excel, and PowerPoint guide covers this in depth, with before-and-after files.
You can chain conversions together. The classic example converts a DOCX body to PDF, then merges it with a pre-designed cover page:
const body = await convertapi.convert('pdf', {
File: './files/service-agreement.docx'
}, 'docx');
const merged = await convertapi.convert('merge', {
Files: ['./files/cover-page.pdf', body.file]
}, 'pdf');
await merged.saveFiles('./output/final-document.pdf');
Note the body.file in the second call. It passes the uploaded result straight into the next step, so nothing gets downloaded and re-uploaded in between. For long chains, conversion workflows run the whole pipeline on the server in a single request.
Every file below is a real input or output of the exact code above:
Yes, and that is the main reason to use an API here. The conversion happens on the server with true Word fidelity, so your Node process needs no local office suite. The code runs unchanged in containers and serverless functions.
No. The html to pdf conversion renders the page on the API side. Puppeteer is still a fine choice if you already run that infrastructure. The API trades that upkeep for a per-conversion cost.
Each convert() call is independent, so standard concurrency works. Map your file list to promises and await Promise.all(...). For multi-step processing of the same document, chain the calls or use a server-side workflow.
The same three-line pattern handles 500+ conversions, including XLSX and PPTX to PDF and images to PDF. It also covers PDF compression, merge, encryption, and PDF/A archiving. Pick a converter on the conversions page and the interactive demo writes the Node.js snippet for you.
One npm package covers the whole conversion surface: DOCX, HTML, and Markdown into PDF, PDF pages back out as images, and multi-step pipelines chained in a few lines. Start with the DOCX to PDF for Node.js page. The free trial includes 250 conversions, which is enough to wire up and test every example in this post.
High-speed DOC/DOCX to PDF API with pixel-perfect accuracy. Enterprise security, advanced parameters, no MS Office required.
Convert HTML files or live web page URLs to PDF with Chrome headless: pixel-perfect rendering, JS/CSS injection, AdBlock.
Convert Markdown to PDF preserving syntax, tables, code blocks, and images with custom page size, orientation, and margins.
Render PDF pages to JPG images with password support, page range selection, resolution control, and JPEG quality settings.
Convert PDFs to editable DOCX preserving layout, text, images, and tables with password, page ranges, layout mode, and OCR.