This API is currently in BETA. If you encounter any issues or have feedback, please contact us or click the chat icon in the bottom right corner.
The Office to PDF API enables seamless conversion of over 130 document formats to PDF, including .docx
, .xlsx
, .pptx
, and more. Whether you need high-quality conversions, custom PDF properties, or to merge multiple files, this API simplifies the process.
You can convert documents from a wide range of formats. Below are some of the supported file types categorized by their format type:
.doc
.docx
.dotx
.rtf
.odt
.txt
.abw
...
.xls
.xlsx
.csv
.ods
.sdc
...
.ppt
.pptx
.odp
.sxi
.pot
...
.bmp
.gif
.jpeg
.png
.svg
.tiff
...
See full list of supported formats...
Unlike other APIs, the Office to PDF API consumes multipart/form-data
instead of application/json
. This is because the API requires the office document file to be uploaded as binary data in the request body.
The API returns a task object as a response. Please refer to the Task Object documentation for more information on how to monitor your conversion progress.
Before converting an office document to PDF, let's check out the available options and how to use the API.
The maximum file size for each document is 5MB, and the maximum files per request is 10. If you need to convert larger files or more files, please contact us.
The properties
field in the request body allows you to set the page properties for the PDF.
Key | Description | Default |
---|---|---|
landscape | Set the paper orientation to landscape. | false |
nativePageRanges | Page ranges to print, e.g., '1-4'. Empty means all pages. | All pages |
exportFormFields | Specify whether form fields are exported as widgets or only as their fixed print representation. | true |
allowDuplicateFieldNames | Allow multiple form fields to have the same field name. | false |
exportBookmarks | Export bookmarks to the PDF. | true |
exportBookmarksToPdfDestination | Export bookmarks as Named Destination. | false |
exportPlaceholders | Export placeholder fields' visual markings only. | false |
exportNotes | Export notes to the PDF. | false |
exportNotesPages | Export notes pages, available in Impress documents only. | false |
exportOnlyNotesPages | Export only notes pages if exportNotesPages is set to true. | false |
exportNotesInMargin | Export notes in the margins to PDF. | false |
convertOooTargetToPdfTarget | Convert LibreOffice links with .od[tpgs] extensions to .pdf . | false |
exportLinksRelativeFsys | Export file system-related hyperlinks as relative to the source document location. | false |
exportHiddenSlides | Export hidden slides from LibreOffice Impress presentations. | false |
skipEmptyPages | Suppress automatically inserted empty pages (Writer documents only). | false |
addOriginalDocumentAsStream | Embed the original document as a stream in the PDF for archiving purposes. | false |
singlePageSheets | Place each spreadsheet sheet (even hidden ones) on a single PDF page. | false |
landscape
orientationformData.append('properties[landscape]', true);
Control the image quality and resolution of the exported PDF.
Key | Description | Default |
---|---|---|
losslessImageCompression | Use lossless image compression (like PNG) or lossy compression (like JPEG). | false |
quality | Set the JPG export quality between 1 and 100. Higher values produce better quality images. | 90 |
reduceImageResolution | Reduce image resolution to the value set by maxImageResolution . | false |
maxImageResolution | If reduceImageResolution is true, reduce images to the given DPI: 75, 150, 300, 600, or 1200. | 300 |
formData.append('quality', 95);
The merge
field in the request body allows you to merge multiple office documents into a single PDF. The default value is false
. If you are sending multiple files, this field must be set to true
.
Key | Description | Default |
---|---|---|
merge | Merge alphanumerically the resulting PDFs. | false |
Alphanumerically means numbers first, then letters in alphabetical order.
The metadata field allows you to embed metadata into the PDF file.
Key | Description | Default |
---|---|---|
metadata | The metadata to write (in JSON format). | None |
Note: Not all metadata fields are writable. See ExifTool documentation for details.
Here is the full structure of the available options:
type PageProperties = {
landscape?: boolean;
nativePageRanges?: {
from: number;
to: number;
};
exportFormFields?: boolean;
singlePageSheets?: boolean;
allowDuplicateFieldNames?: boolean;
exportBookmarks?: boolean;
exportBookmarksToPdfDestination?: boolean;
exportPlaceholders?: boolean;
exportNotes?: boolean;
exportNotesPages?: boolean;
exportOnlyNotesPages?: boolean;
exportNotesInMargin?: boolean;
convertOooTargetToPdfTarget?: boolean;
exportLinksRelativeFsys?: boolean;
exportHiddenSlides?: boolean;
skipEmptyPages?: boolean;
addOriginalDocumentAsStream?: boolean;
};
type Body = {
files: Array<File>;
properties?: PageProperties;
pdfUA?: boolean;
merge?: boolean;
metadata?: any;
losslessImageCompression?: boolean;
reduceImageResolution?: boolean;
quality?: number;
maxImageResolution?: 75 | 150 | 300 | 600 | 1200;
};
If you want to get the PDF as a buffer, you just need to put /buffer
at the end of the URL.
fetch('/api/v1/office/convert/buffer')
.docx
File to PDFconst formData = new FormData();
formData.append('files', file); // file is the .docx file
fetch('/api/v1/office/convert', {
headers: {
'x-api-key': process.env.MARKUPGO_API_KEY
},
method: 'POST',
body: formData,
}).then((response) => response.json());
The merge
option must be set to true
to merge multiple files into a single PDF.
const formData = new FormData();
formData.append('files', file1); // file1 is the .docx file
formData.append('files', file2); // file2 is the .xlsx file
formData.append('merge', true);
fetch('/api/v1/office/convert', {
headers: {
'x-api-key': process.env.MARKUPGO_API_KEY
},
method: 'POST',
body: formData,
}).then((response) => response.json());
.docx
File to PDF with Custom OptionsThis example shows how to define nested keys in the properties
field using the FormData
object.
const formData = new FormData();
formData.append('files', file); // file is the .docx file
formData.append('properties[landscape]', true);
fetch('/api/v1/office/convert', {
headers: {
'x-api-key': process.env.MARKUPGO_API_KEY
},
method: 'POST',
body: formData,
}).then((response) => response.json());
If you encounter issues, check for the following:
.123
.602
.abw
.bib
.cwk
.dbf
.doc
.docm
.docx
.dot
.dotm
.dotx
.lwp
.mcw
.odm
.odt
.rtf
.sxw
.txt
.uot
.wpd
.wps
.zabw
.csv
.dif
.fods
.numbers
.ods
.ots
.sdc
.slk
.stc
.sxc
.xls
.xlsb
.xlsm
.xlsx
.xlt
.xltm
.xltx
.xlw
.fodp
.key
.odp
.otp
.pot
.potm
.potx
.pps
.ppt
.pptm
.pptx
.sdd
.sdp
.sti
.sxi
.bmp
.cdr
.cgm
.cmx
.dbf
.dxf
.emf
.eps
.fodg
.gif
.jpeg
.jpg
.met
.pbm
.pcd
.pct
.pcx
.pgm
.png
.ppm
.psd
.ras
.sgl
.svg
.svm
.swf
.tga
.tif
.tiff
.vdx
.vor
.vsd
.vsdm
.vsdx
.wb2
.wks
.wmf
.xbm
.xpm
.bib
.epub
.htm
.html
.mml
.odd
.oth
.pdf
.pub
.pxl
.sda
.sgl
.sxg
.uof
.uop
.uos
.vor
.xml
.xhtml
Templates
Templates are reusable HTML, CSS, and JavaScript snippets that can be used to generate PDFs or images.
Image Transformation
The Image Transformation API allows you to transform images on-the-fly. You can resize, crop, rotate, and apply various filters to images. The API is designed to be simple and easy to use, and it is optimized for performance.