Convert MS Office to Image Files in Linux

To convert an Office document to an image, post a multipart request to the /render endpoint, including the Office file as the input. In response, you’ll receive a ZIP archive containing all of the document’s pages as images.

Converting an Office document to an image requires you to provide dimensions for the resulting rendered pages via a width or height option.

Note that either the width or height — but not both — is required. The other dimension is calculated before rendering, so as to preserve the page aspect ratio of the rendered image.

The format of the rendered images can be controlled via a format option. Supported image formats are png (default), jpeg, and webp.

Before you get started, make sure Processor is up and running.

Converting an Office File on Disk to an Image

Send a request to the /render endpoint, attaching an input file and the options JSON:

curl -X POST http://localhost:5000/render \
  -F file=@example.docx \
  -F options='{
  "options": {
    "width": 1000,
    "format": "png"
  }
}' \
  -o result.zip
POST /render HTTP/1.1
Content-Type: multipart/form-data; boundary=customboundary

--customboundary
Content-Disposition: form-data; name="file"; filename="example.docx"


--customboundary
Content-Disposition: form-data; name="options"
Content-Type: application/json

{
  "options": {
    "width": 1000,
    "format": "png"
  }
}
--customboundary--

Converting an Office File from a URL to an Image

Send a request to the /render endpoint, attaching a URL pointing to an input file and the options JSON:

curl -X POST http://localhost:5000/render \
  -F url=https://pspdfkit.com/downloads/examples/paper.docx \
  -F options='{
  "options": {
    "width": 1000,
    "format": "png"
  }
}' \
  -o result.zip
POST /render HTTP/1.1
Content-Type: multipart/form-data; boundary=customboundary

--customboundary
Content-Disposition: form-data; name="url"

https://pspdfkit.com/downloads/examples/paper.docx
--customboundary
Content-Disposition: form-data; name="options"
Content-Type: application/json

{
  "options": {
    "width": 1000,
    "format": "png"
  }
}
--customboundary--