Convert Office files to PDF

This guide explains how to convert Office files to PDF using Document Engine.

Requirements

Ensure Document Engine is up and running. If you haven’t set it up yet, refer to our getting started guides, select the deployment option you prefer, and follow the instructions.

Converting an Office file from disk

To convert an Office file from disk, send a request to the /api/build endpoint, including both the Office file as input and the instructions JSON.

The default output from the /api/build endpoint is a PDF file. You can also specify other file types. Learn more about the output options in our API reference.

Terminal window
curl -X POST http://localhost:5000/api/build \
-H "Authorization: Token token=<API token>" \
-F document=@/path/to/example-document.docx \
-F instructions='{
"parts": [
{
"file": "document"
}
]
}' \
-o result.pdf

Converting with markup mode

To control how markup (user comments, modification suggestions) is preserved during Office conversion, specify the markup_mode parameter. This parameter accepts the following values:

  • noMarkup — Render the document as if all changes were accepted (default).
  • original — Render the document as if all changes were rejected.
  • simpleMarkup — Render with changes accepted and comments as annotations.
  • allMarkup — Render with all markups visible, including redlines and comments.
Terminal window
curl -X POST http://localhost:5000/api/build \
-H "Authorization: Token token=<API token>" \
-F document=@/path/to/example-document.docx \
-F instructions='{
"parts": [
{
"file": "document",
"markup_mode": "allMarkup"
}
]
}' \
-o result.pdf

Converting an Office file from URL

To convert an Office file from a URL, send a multipart request to the /api/build endpoint, attaching a URL pointing to the Office file:

Terminal window
curl -X POST http://localhost:5000/api/build \
-H "Authorization: Token token=<API token>" \
-F instructions='{
"parts": [
{
"file": {
"url": "https://www.nutrient.io/downloads/examples/paper.docx"
}
}
]
}' \
-o result.pdf

Converting with markup mode

You can also use the markup_mode parameter with URL-based conversions. See the converting with markup mode section under disk conversion for the available parameter values and their descriptions.

Terminal window
curl -X POST http://localhost:5000/api/build \
-H "Authorization: Token token=<API token>" \
-F instructions='{
"parts": [
{
"file": {
"url": "https://www.nutrient.io/downloads/examples/paper.docx"
},
"markup_mode": "allMarkup"
}
]
}' \
-o result.pdf