This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /blog/how-to-convert-word-to-pdf-using-javascript.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. How to convert DOCX to PDF in JavaScript

Table of contents

    How to convert DOCX to PDF in JavaScript
    Summary
    • 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.
    Explore Demo

    Prerequisites

    Adding Nutrient to your project

    1. Install the @nutrient-sdk/viewer package:

      Terminal window
      npm i @nutrient-sdk/viewer
    2. 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.js
    • nutrient-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.

    1. Add a Word document named document.docx to your project directory. Any DOC or DOCX file works.

    2. 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>
    3. 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);
      });
    4. Serve your project:

      Terminal window
      npx serve -l 8080 .
    5. 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:

    FAQ

    Does this require Microsoft Office on my server?

    No. Nutrient Web SDK converts Word documents entirely in the browser. No server-side Office installation needed.

    What Word formats are supported?

    Both DOC and DOCX formats are supported.

    Can I customize the output PDF?

    Yes. You can specify PDF/A conformance levels for archival, control output quality, and more. See the configuration options.

    What happens with custom fonts?

    Nutrient substitutes unavailable fonts with equivalents to ensure consistent rendering without requiring font licenses.

    Can I edit the Word document before converting?

    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.

    Hulya Masharipov

    Hulya Masharipov

    Technical Writer

    Hulya is a frontend web developer and technical writer who enjoys creating responsive, scalable, and maintainable web experiences. She’s passionate about open source, web accessibility, cybersecurity privacy, and blockchain.

    Explore related topics

    Nutrient SDK Convert and process PDFs at scale