> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/ms-office/convert-office.md).

# Convert MS Office (Word, Excel, PowerPoint) to PDF Using JavaScript

Convert Microsoft Office files (Word, Excel, PowerPoint) to PDFs in-browser with Apryse's Web SDK, using WebViewer without third-party dependencies. Install WebViewer, configure it, and execute docume

{% hint style="info" %}
**Requirements**

*These packages are required to use these features in production. Trial keys have unlimited access to all features*

<a href="https://apryse.com/capabilities#OfficeConversion" class="button primary">Package: Office Conversion</a><a href="https://showcase.apryse.com/office-documents" class="button primary">Live demo</a>
{% endhint %}

Convert an MS Office file to a PDF document without any external third-party dependencies in a browser. WebViewer already allows you to [view](/web/ms-office/open-office.md) Office documents. The below sample shows how to convert the Office document to a PDF, without initializing WebViewer UI. (You can also check out our [MS Office to PDF demo](https://showcase.apryse.com/office-to-pdf) now.)

## Setup

1. Install WebViewer by running `npm i @pdftron/webviewer` or download it [here](https://docs.apryse.com/downloads/WebViewer.zip).
2. Copy `core` folder from `node_modules/@pdftron/webviewer/public/core` (if you downloaded the SDK, you will find `core` folder in `WebViewer/lib/`) to a location that can serve static assets. For example, `public` folder in a React app.
3. Reference `webviewer-core.min.js` script in `index.html` and create a JS function to perform the conversion.

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}

<pre class="language-js" data-line-numbers><code class="lang-js">&#x3C;html>
  &#x3C;body>
    &#x3C;script src="../core/webviewer-core.min.js">&#x3C;/script>
    &#x3C;script>
    (async function() {
      Core.setWorkerPath('../core');
      const licenseKey = '<code class="expression">visitor.claims.wvKey || "YOUR_LICENSE_KEY"</code>';
      await Core.PDFNet.initialize(licenseKey);

      // perform the conversion with no optional parameters
      const buf = await Core.officeToPDFBuffer('/path/to/file.docx');

      //optionally save the blob to a file or upload to a server
      const blob = new Blob([buf], { type: 'application/pdf' });
      
      // As an example. you can save the file with the following code
      // Create a temporary anchor element
      const blobUrl = URL.createObjectURL(blob);
      const link = document.createElement("a");
      link.href = blobUrl;
      link.download = "my_file.pdf";
      
      // Trigger the download
      link.click();
      
      // Clean up
      document.body.removeChild(link);
      URL.revokeObjectURL(blobUrl);

    })()
    &#x3C;/script>
  &#x3C;/body>
&#x3C;/html>
</code></pre>

[Core.setWorkerPath](https://sdk.apryse.com/api/web/Core.html#.setWorkerPath__anchor) [Core.office2PDFBuffer](https://sdk.apryse.com/api/web/Core.html#.office2PDFBuffer__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}

<pre class="language-js" data-line-numbers><code class="lang-js">&#x3C;html>
  &#x3C;body>
    &#x3C;script src="../core/CoreControls.js">&#x3C;/script>
    &#x3C;script>
    (async function() {
      CoreControls.setWorkerPath('../core');
      const licenseKey = '<code class="expression">visitor.claims.wvKey || "YOUR_LICENSE_KEY"</code>';
      await PDFNet.initialize();

      // perform the conversion with no optional parameters
      const buf = await CoreControls.office2PDFBuffer('/path/to/file.docx', { l: licenseKey });

      //optionally save the blob to a file or upload to a server
      const blob = new Blob([buf], { type: 'application/pdf' });
    })()
    &#x3C;/script>
  &#x3C;/body>
&#x3C;/html>
</code></pre>

[CoreControls.setWorkerPath](https://sdk.apryse.com/api/web/Core.html#.setWorkerPath__anchor) [CoreControls.office2PDFBuffer](https://sdk.apryse.com/api/web/Core.html#.office2PDFBuffer__anchor)
{% endtab %}
{% endtabs %}

## Additional font resources

WebViewer will automatically use substitute fonts hosted on a web server when a font is not embedded in the source document. The fallback fonts are hosted with Apryse by default but if this is a concern, you can host the fonts on your own servers. See this [FAQ](/web/get-started/faq/self-serve-substitute-fonts.md) for more details.

## Related blogs

**DOCX to PDF** [How to Generate DOCX and Save As a PDF](https://apryse.com/blog/javascript/generate-docx-and-save-as-pdf-in-javascript) (in Javascript) - 1/10/2022 [How to Convert DOCX Files to PDF with Node.js](https://apryse.com/blog/nodejs/generate-pdf-convert-docx-to-pdf-with-nodejs) - 4/24/2020


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/web/ms-office/convert-office.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
