Api

Office to PDF (BETA)

Convert 130+ office documents to PDF using the Office to PDF API.

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.

Supported Formats

You can convert documents from a wide range of formats. Below are some of the supported file types categorized by their format type:

Word Processing

.doc .docx .dotx .rtf .odt .txt .abw ...

Spreadsheets

.xls .xlsx .csv .ods .sdc ...

Presentations

.ppt .pptx .odp .sxi .pot ...

Graphics & Images

.bmp .gif .jpeg .png .svg .tiff ...

See full list of supported formats...


Before You Begin

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.

Limitations and Constraints

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.


Options

Page Properties

The properties field in the request body allows you to set the page properties for the PDF.

KeyDescriptionDefault
landscapeSet the paper orientation to landscape.false
nativePageRangesPage ranges to print, e.g., '1-4'. Empty means all pages.All pages
exportFormFieldsSpecify whether form fields are exported as widgets or only as their fixed print representation.true
allowDuplicateFieldNamesAllow multiple form fields to have the same field name.false
exportBookmarksExport bookmarks to the PDF.true
exportBookmarksToPdfDestinationExport bookmarks as Named Destination.false
exportPlaceholdersExport placeholder fields' visual markings only.false
exportNotesExport notes to the PDF.false
exportNotesPagesExport notes pages, available in Impress documents only.false
exportOnlyNotesPagesExport only notes pages if exportNotesPages is set to true.false
exportNotesInMarginExport notes in the margins to PDF.false
convertOooTargetToPdfTargetConvert LibreOffice links with .od[tpgs] extensions to .pdf.false
exportLinksRelativeFsysExport file system-related hyperlinks as relative to the source document location.false
exportHiddenSlidesExport hidden slides from LibreOffice Impress presentations.false
skipEmptyPagesSuppress automatically inserted empty pages (Writer documents only).false
addOriginalDocumentAsStreamEmbed the original document as a stream in the PDF for archiving purposes.false
singlePageSheetsPlace each spreadsheet sheet (even hidden ones) on a single PDF page.false

Example: Setting landscape orientation

formData.append('properties[landscape]', true);

Images

Control the image quality and resolution of the exported PDF.

KeyDescriptionDefault
losslessImageCompressionUse lossless image compression (like PNG) or lossy compression (like JPEG).false
qualitySet the JPG export quality between 1 and 100. Higher values produce better quality images.90
reduceImageResolutionReduce image resolution to the value set by maxImageResolution.false
maxImageResolutionIf reduceImageResolution is true, reduce images to the given DPI: 75, 150, 300, 600, or 1200.300

Example: Setting image quality

formData.append('quality', 95);

Merge

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.

KeyDescriptionDefault
mergeMerge alphanumerically the resulting PDFs.false

Alphanumerically means numbers first, then letters in alphabetical order.


Metadata

The metadata field allows you to embed metadata into the PDF file.

KeyDescriptionDefault
metadataThe metadata to write (in JSON format).None

Note: Not all metadata fields are writable. See ExifTool documentation for details.


Complete Options

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;
};

Getting buffer response

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')

Example Usage

Convert a .docx File to PDF

const 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());

Convert Multiple Files to PDF with Merging

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());

Convert a .docx File to PDF with Custom Options

This 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());

Troubleshooting

If you encounter issues, check for the following:

  • File too large: Ensure your file size does not exceed the maximum limit.
  • Unsupported file types: Double-check that the file format is supported by referring to the supported formats.
  • Invalid API key: Verify your API key is valid and has the correct permissions.

Full List of Supported Formats

Word Processing

.123 .602 .abw .bib .cwk .dbf .doc .docm .docx .dot .dotm .dotx .lwp .mcw .odm .odt .rtf .sxw .txt .uot .wpd .wps .zabw

Spreadsheets

.csv .dif .fods .numbers .ods .ots .sdc .slk .stc .sxc .xls .xlsb .xlsm .xlsx .xlt .xltm .xltx .xlw

Presentations

.fodp .key .odp .otp .pot .potm .potx .pps .ppt .pptm .pptx .sdd .sdp .sti .sxi

Graphics and Images

.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

Others

.bib .epub .htm .html .mml .odd .oth .pdf .pub .pxl .sda .sgl .sxg .uof .uop .uos .vor .xml .xhtml