---
title: "Convert Office (DOCX, XLSX, PPTX) to PDF in React | Nutrient"
canonical_url: "https://www.nutrient.io/guides/web/conversion/office-to-pdf/react/"
md_url: "https://www.nutrient.io/guides/web/conversion/office-to-pdf/react.md"
last_updated: "2026-11-13T14:49:37.347Z"
description: "Convert Office (DOCX, XLSX, PPTX) to PDF in React | guide for Nutrient Web SDK with detailed instructions and code examples."
---

# Convert Office to PDF in React

Nutrient Web SDK is a client-side JavaScript library that’s fully compatible with React. It converts Office documents to PDF directly in the browser and doesn’t require server-side processing.

To convert Office files such as DOCX, XLSX, and PPTX to PDF, Nutrient Web SDK uses its own conversion engine. It doesn’t depend on third-party tools such as LibreOffice or Microsoft Office. For supported Office formats, refer to the [list of supported file types](https://www.nutrient.io/guides/web/about/file-type-support.md) guide.

[Try for free](https://www.nutrient.io/sdk/web/getting-started.md)

[Launch demo](https://www.nutrient.io/demo/convert-office-to-pdf)

## Converting Office documents to PDFs after displaying

To convert an Office document to PDF after loading it in the viewer:

1. [Load the source Office document](https://www.nutrient.io/guides/web/open-a-document.md) (optional). If you want to load the document without showing the UI, use the `headless` parameter.

2. Make changes to the document (optional). For example, [add annotations](https://www.nutrient.io/guides/web/annotations/create-edit-and-remove/create.md).

3. Convert the source document to PDF with [`exportPDF`](https://www.nutrient.io/api/web/classes/NutrientViewer.Instance.html#exportpdf) (optional). Use the `outputFormat` flag if you want a PDF/A output. For more information, refer to the [converting PDF to PDF/A](https://www.nutrient.io/guides/web/conversion/to-pdfa.md) guide.

4. Save the output document. `exportPDF` returns a `Promise` that resolves to an `ArrayBuffer` with the output PDF. Use that buffer to download the file or store it. For more information, refer to the [guides on saving a document](https://www.nutrient.io/guides/web/save-a-document.md).

The following example loads an Office document and exports it to PDF:

```js

NutrientViewer.load({
  container: "#pspdfkit",

  document: "source.docx",
  licenseKey: "YOUR_LICENSE_KEY"
}).then((instance) => {
  instance.exportPDF();
});

```

The following example loads an Office document, exports it to PDF with conformance level PDF/A-4f, and downloads it in the client browser:

```js

NutrientViewer.load({
  container: "#pspdfkit",

  document: "source.docx",
  licenseKey: "YOUR_LICENSE_KEY"
}).then((instance) =>
    instance.exportPDF({
      outputFormat: {
        conformance: NutrientViewer.Conformance.PDFA_4F
      }
    })
  ).then(function (buffer) {
    const blob = new Blob([buffer], { type: "application/pdf" });
    const objectUrl = window.URL.createObjectURL(blob);
    downloadPdf(objectUrl);
    window.URL.revokeObjectURL(objectUrl);
  });
function downloadPdf(blob) {
  const a = document.createElement("a");
  a.href = blob;
  a.style.display = "none";
  a.download = "output.pdf";
  a.setAttribute("download", "output.pdf");
  document.body.appendChild(a);
  a.click();
  document.body.removeChild(a);
}

```

When you export a document, you can choose how Nutrient Web SDK writes the output. For more information, refer to the [flattening annotations](https://www.nutrient.io/guides/web/annotations/flatten.md) guide and the [incremental saving](https://www.nutrient.io/guides/web/features/document-processing.md) guide.

Use autosave to configure when Nutrient Web SDK saves changes. For more information, refer to the [autosave](https://www.nutrient.io/guides/web/features/saving.md) guide.

Call [`instance.save()`](https://www.nutrient.io/api/web/classes/NutrientViewer.Instance.html#save) before exporting if autosave is disabled, or after an undo, redo, or paste. Otherwise, the exported file doesn’t include unsaved annotations.






### Converting Office documents with custom fonts to PDFs after displaying

When you convert an Office document with custom fonts to PDF, Nutrient Web SDK can’t access those fonts by default because of licensing constraints. In that case, it substitutes missing fonts with equivalents (for example, Arial with Noto).

If you want the output PDF to use the same fonts as the source document, provide paths to the custom font files.

To convert an Office document with custom fonts after loading it in the viewer:

1. Load custom fonts. For more information, refer to the [adding custom fonts](https://www.nutrient.io/guides/web/features/custom-fonts.md#standalone-deployments) guide.

2. [Load the source Office document](https://www.nutrient.io/guides/web/open-a-document.md) (optional). If you want to load the document without showing the UI, use the `headless` parameter.

3. Make changes to the document (optional). For example, [add annotations](https://www.nutrient.io/guides/web/annotations/create-edit-and-remove/create.md).

4. Convert the source document to PDF with [`exportPDF`](https://www.nutrient.io/api/web/classes/NutrientViewer.Instance.html#exportpdf) (optional). Use the `outputFormat` flag if you want a PDF/A output. For more information, refer to the [converting PDF to PDF/A](https://www.nutrient.io/guides/web/conversion/to-pdfa.md) guide.

5. Save the output document. `exportPDF` returns a `Promise` that resolves to an `ArrayBuffer` with the output PDF. Use that buffer to download the file or store it. For more information, refer to the [guides on saving a document](https://www.nutrient.io/guides/web/save-a-document.md).

The following example loads an Office document and exports it to PDF:

```js

const fetchFont = (fontFileName) =>
  fetch(`https://example.com/${fontFileName}`).then((r) => {
    if (r.status === 200) {
      return r.blob();
    } else {
      throw new Error();
    }
  });

const customFonts = ["arial.ttf", "helvetica.ttf", "tahoma.ttf"].map(
  (font) => new NutrientViewer.Font({ name: font, callback: fetchFont })
);

NutrientViewer.load({
  customFonts,
  container: "#pspdfkit",

  document: "source.docx",
  licenseKey: "YOUR_LICENSE_KEY"
}).then((instance) => {
  instance.exportPDF();
});

```

When you export a document, you can choose how Nutrient Web SDK writes the output. For more information, refer to the [flattening annotations](https://www.nutrient.io/guides/web/annotations/flatten.md) guide and the [incremental saving](https://www.nutrient.io/guides/web/features/document-processing.md) guide.

Use autosave to configure when Nutrient Web SDK saves changes. For more information, refer to the [autosave](https://www.nutrient.io/guides/web/features/saving.md) guide.

Call [`instance.save()`](https://www.nutrient.io/api/web/classes/NutrientViewer.Instance.html#save) before exporting if autosave is disabled, or after an undo, redo, or paste. Otherwise, the exported file doesn’t include unsaved annotations.






## Converting Office documents to PDFs without displaying

To convert an Office document to PDF without loading it in the viewer:

1. Load and convert the source Office document with [`convertToPDF`](https://www.nutrient.io/api/web/modules/NutrientViewer.html#.convertToPDF).
   - Pass a [`Configuration` object](https://www.nutrient.io/api/web/NutrientViewer.Configuration.html) with the source document path and license key.
   - Optionally pass a `Conformance` enum value for PDF/A output.

2. Save the output document. `convertToPDF` returns a `Promise` that resolves to an `ArrayBuffer` with the output PDF. Use that buffer to download the file or store it. For more information, refer to the [guides on saving a document](https://www.nutrient.io/guides/web/save-a-document.md).

The following example exports the source document to PDF with conformance level PDF/A-4f:

```js

NutrientViewer.convertToPDF(
  {
    document: "source.docx",
    licenseKey: "YOUR_LICENSE_KEY"
  },
  NutrientViewer.Conformance.PDFA_4F
);

```

The following example converts an Office document to PDF and downloads it in the client browser:

```js

NutrientViewer.convertToPDF({
  document: "source.docx",
  licenseKey: "YOUR_LICENSE_KEY"
}).then(function (buffer) {
  const blob = new Blob([buffer], { type: "application/pdf" });
  const objectUrl = window.URL.createObjectURL(blob);
  downloadPdf(objectUrl);
  window.URL.revokeObjectURL(objectUrl);
});
function downloadPdf(blob) {
  const a = document.createElement("a");
  a.href = blob;
  a.style.display = "none";
  a.download = "output.pdf";
  a.setAttribute("download", "output.pdf");
  document.body.appendChild(a);
  a.click();
  document.body.removeChild(a);
}

```

### Converting Office documents with custom fonts to PDFs without displaying

When you convert an Office document with custom fonts to PDF, Nutrient Web SDK can’t access those fonts by default because of licensing constraints. In that case, it substitutes missing fonts with equivalents (for example, Arial with Noto).

If you want the output PDF to use the same fonts as the source document, provide paths to the custom font files.

To convert an Office document with custom fonts without loading it in the viewer:

1. Load custom fonts. For more information, refer to the [adding custom fonts](https://www.nutrient.io/guides/web/features/custom-fonts.md#standalone-deployments) guide.

2. Load and convert the source Office document with [`convertToPDF`](https://www.nutrient.io/api/web/modules/NutrientViewer.html#.convertToPDF).
   - Pass a [`Configuration` object](https://www.nutrient.io/api/web/NutrientViewer.Configuration.html) with the source document path, license key, and custom fonts.
   - Optionally pass a `Conformance` enum value for PDF/A output.

3. Save the output document. `convertToPDF` returns a `Promise` that resolves to an `ArrayBuffer` with the output PDF. Use that buffer to download the file or store it. For more information, refer to the [guides on saving a document](https://www.nutrient.io/guides/web/save-a-document.md).

The following example exports the source document to PDF with conformance level PDF/A-2a:

```js

const fetchFont = (fontFileName) =>
  fetch(`https://example.com/${fontFileName}`).then((r) => {
    if (r.status === 200) {
      return r.blob();
    } else {
      throw new Error();
    }
  });

const customFonts = ["arial.ttf", "helvetica.ttf", "tahoma.ttf"].map(
  (font) => new NutrientViewer.Font({ name: font, callback: fetchFont })
);

NutrientViewer.convertToPDF(
  {
    customFonts,
    document: "source.docx",
    licenseKey: "YOUR_LICENSE_KEY"
  },
  NutrientViewer.Conformance.PDFA_2A
);

```

### Configuring conversion from Excel documents to PDF

Use these properties to configure Excel-to-PDF conversion:

- `splitExcelSheetsIntoPages` — Set to `true` to export each sheet as a separate PDF page. Default: `false`.

- `spreadsheetRenderOnlyPrintArea` — Set to `true` to render only each sheet’s defined print area. If no print area exists, the converter renders the full sheet. Default: `true`.

- `spreadsheetMaximumContentHeightPerSheet` — Sets the maximum content height (in millimeters) per sheet. Use this to manage memory usage. Default: `0` (unlimited).

- `spreadsheetMaximumContentWidthPerSheet` — Sets the maximum content width (in millimeters) per sheet. Use this to manage memory usage. Default: `0` (unlimited).

#### Example using NutrientViewer.convertToPDF()

```js

NutrientViewer.convertToPDF({
  document: "source.xlsx",
  licenseKey: "YOUR_LICENSE_KEY",
}, null, {
  splitExcelSheetsIntoPages: true,
  spreadsheetRenderOnlyPrintArea: false,
  spreadsheetMaximumContentHeightPerSheet: 2000,
  spreadsheetMaximumContentWidthPerSheet: 200
});

```

#### Example using NutrientViewer.load()

```js

NutrientViewer.load({
  document: "source.xlsx",
  licenseKey: "YOUR_LICENSE_KEY",
  officeConversionSettings: {
    splitExcelSheetsIntoPages: true,
    spreadsheetRenderOnlyPrintArea: false,
    spreadsheetMaximumContentHeightPerSheet: 2000,
    spreadsheetMaximumContentWidthPerSheet: 200
  }
});

```

### Configuring conversion from Word documents to PDF

You can configure Word-to-PDF conversion by choosing how revision history is rendered.

- `documentMarkupMode` sets the markup mode:
  - `noMarkup` — Renders the document as if all changes were accepted. Comments aren’t converted to comment annotations. This is the default.
  - `original` — Renders the document as if all changes were rejected (as if there were no redlines). Comments aren’t converted to comment annotations.
  - `simpleMarkup` — Renders the document as if all changes were accepted. Comments are converted to comment annotations.
  - `allMarkup` — Renders the document with all markups. Redlines appear as redlines, and comments are converted to comment annotations.

Default value: `noMarkup`.

#### Example using NutrientViewer.convertToPDF()

```js

NutrientViewer.convertToPDF({
  document: "source.docx",
  licenseKey: "YOUR_LICENSE_KEY",
}, null, {
  documentMarkupMode: 'simpleMarkup',
});

```

#### Example using NutrientViewer.load()

```js

NutrientViewer.load({
  document: "source.docx",
  licenseKey: "YOUR_LICENSE_KEY",
  officeConversionSettings: {
    documentMarkupMode: 'simpleMarkup',
  }
});

```

When you export a document, you can choose how Nutrient Web SDK writes the output. For more information, refer to the [flattening annotations](https://www.nutrient.io/guides/web/annotations/flatten.md) guide and the [incremental saving](https://www.nutrient.io/guides/web/features/document-processing.md) guide.

Use autosave to configure when Nutrient Web SDK saves changes. For more information, refer to the [autosave](https://www.nutrient.io/guides/web/features/saving.md) guide.

Call [`instance.save()`](https://www.nutrient.io/api/web/classes/NutrientViewer.Instance.html#save) before exporting if autosave is disabled, or after an undo, redo, or paste. Otherwise, the exported file doesn’t include unsaved annotations.






### Canceling a conversion

To cancel a conversion in progress, pass an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) through the [`signal`](https://www.nutrient.io/api/web/NutrientViewer.Configuration.html#signal) configuration option:

When the signal is aborted, the conversion promise rejects with a `DOMException` whose name is `AbortError`. HTTP-based steps (such as document fetch) are canceled at the network level. For WebAssembly/worker-based processing, the promise still rejects immediately, but underlying processing may continue in the background briefly.

```js

const controller = new AbortController();

NutrientViewer.convertToPDF({
  document: "source.docx",
  licenseKey: "YOUR_LICENSE_KEY",
  signal: controller.signal,
}).catch((error) => {
  if (error.name === "AbortError") {
    console.log("Conversion cancelled");
  }
});

// Cancel the conversion.
controller.abort();

```
---

> Part of [Convert Office to PDF using JavaScript](/guides/web/conversion/office-to-pdf.md)

## Related pages

- [Convert Office to PDF in Angular](/guides/web/conversion/office-to-pdf/angular.md)
- [Convert Office to PDF in ASP.NET](/guides/web/conversion/office-to-pdf/aspnet.md)
- [Convert Office to PDF in Blazor](/guides/web/conversion/office-to-pdf/blazor.md)
- [Convert Office to PDF in Electron](/guides/web/conversion/office-to-pdf/electron.md)
- [Convert Office to PDF in HTML5](/guides/web/conversion/office-to-pdf/html5.md)
- [Convert Office to PDF in jQuery](/guides/web/conversion/office-to-pdf/jquery.md)
- [Convert Office to PDF in Next.js](/guides/web/conversion/office-to-pdf/nextjs.md)
- [Convert Office to PDF in Nuxt.js](/guides/web/conversion/office-to-pdf/nuxtjs.md)
- [Convert Office to PDF in progressive web apps](/guides/web/conversion/office-to-pdf/pwa.md)
- [Convert Office to PDF in Svelte](/guides/web/conversion/office-to-pdf/svelte.md)
- [Convert Office to PDF in TypeScript](/guides/web/conversion/office-to-pdf/typescript.md)
- [Convert Office to PDF in Vue.js](/guides/web/conversion/office-to-pdf/vuejs.md)

