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 — Work with the converted PDF using text editing, annotations, and electronic signatures, with the corresponding licensed components.
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?
Some server-side converters depend on Microsoft Office or LibreOffice; others use independent rendering engines. Compare those dependencies, hosting requirements, and licensing when choosing a deployment model.
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.
How to convert DOCX to PDF in JavaScript
The conversion is three calls: Load the DOCX into the viewer, call exportPDF() on the returned instance, and hand the resulting buffer to the browser as a download.
Add a Word document named
document.docxto your project directory. Any DOC or DOCX file works.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
After loading a Word document, you can work with its converted PDF representation using the corresponding licensed components. These changes apply to the PDF output; they don’t edit and save the source DOCX:
- Text editing — Edit text in the converted PDF.
- Page manipulation — Add, remove, or rearrange pages.
- Annotations — Add highlights, comments, or stamps.
- Electronic signatures — Draw, type, or upload a signature appearance. Certificate-based digital signing is a separate capability.
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.
You can edit and annotate the converted PDF representation before exporting it. This workflow doesn’t save edits back to the original Word file. Text editing and electronic signatures require the corresponding licensed components.