How to convert DOCX to PDF in JavaScript
Table of contents
- Client-side conversion — Convert Word documents to PDF directly in the browser. No server required.
- No MS Office dependency — Nutrient Web SDK handles conversion without Microsoft Office or LibreOffice.
- Beyond conversion — The same SDK supports text editing, annotations, and digital signatures on Office files.
In this tutorial, you’ll learn how to convert Word documents (DOC and DOCX) to PDF using JavaScript. The conversion happens entirely in the browser — no server-side processing needed.
Why convert Word to PDF in the browser?
Server-side Word-to-PDF conversion typically requires MS Office or LibreOffice installed on your server. That adds deployment complexity, licensing costs, and potential security concerns.
Nutrient Web SDK runs entirely in the browser:
- No server dependencies — Deploy to any static host. No Office installation, no LibreOffice, no server-side processing.
- No licensing headaches — Skip MS Office licenses for your servers.
- Works offline — Once loaded, conversion works without network requests.
- User privacy — Documents never leave the user’s browser.
What you can build
- Document portals — Let users convert and download Office files as PDFs.
- Form workflows — Convert filled Word templates to PDF for archiving.
- Review systems — Add annotations to Word docs. Then export as PDF.
- E-signature flows — Load a Word contract, add signatures, export as PDF.
Prerequisites
- Node.js(opens in a new tab) (latest stable version)
- npm (comes with Node.js)
Adding Nutrient to your project
Install the
@nutrient-sdk/viewerpackage:Copy the viewer assets to your project:
Terminal window cp -R ./node_modules/@nutrient-sdk/viewer/dist/ ./assets/
Your assets directory should contain:
nutrient-viewer.jsnutrient-viewer-lib/directory
Make sure your server has the Content-Type: application/wasm MIME type set. See the troubleshooting guide if you encounter issues.
Converting Word to PDF
Add a Word document to your project directory. You can use our demo document.
Create your HTML file:
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Word to PDF Converter</title></head><body><div id="nutrient" style="width: 100%; height: 100vh;"></div><script type="module" src="index.js"></script></body></html>Create
index.js:import "./assets/nutrient-viewer.js";const baseUrl = `${window.location.protocol}//${window.location.host}/assets/`;NutrientViewer.load({baseUrl,container: "#nutrient",document: "document.docx",}).then((instance) => {// Convert to PDF.return instance.exportPDF();}).then((buffer) => {// Download the PDF.const blob = new Blob([buffer], { type: "application/pdf" });const url = URL.createObjectURL(blob);const a = document.createElement("a");a.href = url;a.download = "output.pdf";document.body.appendChild(a);a.click();document.body.removeChild(a);URL.revokeObjectURL(url);}).catch((error) => {console.error("Error:", error.message);});Serve your project:
Terminal window npx serve -l 8080 .Open http://localhost:8080. The PDF downloads automatically.
Exporting as PDF/A
For archival purposes, export as PDF/A:
instance.exportPDF({ outputFormat: { conformance: NutrientViewer.Conformance.PDFA_4F, },});See the PDF/A conversion guide for more options.
Beyond conversion
Once you’ve loaded a Word document, you can do more than convert it:
- Text editing — Edit text directly in the Word document.
- Page manipulation — Add, remove, or rearrange pages.
- Annotations — Add highlights, comments, or stamps.
- Digital signatures — Draw, type, or upload signatures.
A note about fonts
When converting Word documents with custom fonts, Nutrient substitutes unavailable fonts with equivalents (e.g. Arial with Noto). This ensures consistent rendering without requiring font licenses on the client.
Conclusion
Converting Word to PDF in the browser removes server-side complexity. No MS Office installation, no LibreOffice, no server to maintain. Nutrient Web SDK handles the conversion client-side, and the same SDK supports editing, annotations, and signatures if you need them later.
To get started:
- Start your free trial to test the SDK.
- Try the demo to see it in action.
FAQ
No. Nutrient Web SDK converts Word documents entirely in the browser. No server-side Office installation needed.
Both DOC and DOCX formats are supported.
Yes. You can specify PDF/A conformance levels for archival, control output quality, and more. See the configuration options.
Nutrient substitutes unavailable fonts with equivalents to ensure consistent rendering without requiring font licenses.
Yes. Nutrient Web SDK supports text editing, annotations, and digital signatures on Word documents before export.