Conversion API

For the interaction with the document conversion service the POST requests are used. The request parameters are entered in JSON format in the request body. The requests are sent to the https://documentserver/ConvertService.ashx address where documentserver is the name of the server with the ONLYOFFICE Document Server installed.

In ONLYOFFICE Document Server prior to version 4.2 the GET request with the parameters in the QueryString were used.

Request parameters and their description

ParameterDescriptionTypePresence
asyncDefines the conversion request type: asynchronous or not.
Supported values:
  • true
  • false
When the asynchronous request type is used, the response is formed instantly. In this case to get the result it is necessary to send requests without parameter change until the conversion is finished. The default value is false.
booleanoptional
If the conversion is synchronous and the file takes a long time to be converted, a web request timeout error may occur. Although the conversion can be eventually completed, the result can only be obtained by sending the request again with the same key.
codePageDefines the file encoding when converting from csv or txt format.
Main supported values:
  • 932 - Japanese (Shift-JIS),
  • 950 - Chinese Traditional (Big5),
  • 1250 - Central European (Windows),
  • 1251 - Cyrillic (Windows),
  • 65001 - Unicode (UTF-8).
You can find all the supported values in this file.
integeroptional
delimiterDefines the delimiter characters for separating values when converting from csv format.
Supported values:
  • 0 - no delimiter,
  • 1 - tab,
  • 2 - semicolon,
  • 3 - colon,
  • 4 - comma,
  • 5 - space.
integeroptional
documentLayoutDefines the document layout which specifies parameters for printing forms as pdf documents or images.objectoptional
documentLayout.drawPlaceHoldersDefines if placeholders will be drawn or not.booleanoptional
documentLayout.drawFormHighlightDefines if forms will be highlighted or not.booleanoptional
documentLayout.isPrintDefines if the print mode is turned on or off. This parameter is used only for converting docx/docxf into pdf. If this parameter is equal to true, the drawPlaceHolders and drawFormHighlight flags are used as described above. If this parameter is false, the drawFormHighlight flag does not work and the drawPlaceHolders parameter allows saving the forms in the pdf format. The default value is false.booleanoptional
documentRendererDefines the document renderer when converting from pdf, xps, oxps.objectoptional
documentRenderer.textAssociationDefines the rendering mode that can have the following values:
  • blockChar - all text is converted by single characters. Each character is in its own frame (like a textbox),
  • blockLine - all text is converted by separate lines. Each text line is in its own frame. Lines can be combined within the same block,
  • plainLine - all text is converted as a plain text. But each line is a separate paragraph,
  • plainParagraph - all text is converted as a plain text. Lines are combined into paragraphs.
The default value is plainLine.
stringoptional
filetypeDefines the type of the document file to be converted.stringrequired
keyDefines the document identifier used to unambiguously identify the document file.stringrequired
outputtypeDefines the resulting converted document type. Starting from version 7.0, file formats can be specified instead of extensions. They are used when we do not know in advance what extension is required:
  • ooxml - defines that the file will be converted into docx, docm, xlsx, xlsm, pptx or pptm. For example, when the doc file is converted into the OOXML format, the resulting file can be docx or docm if this file contains macros (the same for xls and ppt). It is also applied when converting XML files into OOXML formats (docx, xlsx or pptx depending on the content);
  • odf - defines that the file will be converted into odt, ods or odp. For example, it is used when converting XML files into ODF formats (odt, ods or odp depending on the content).
stringrequired
passwordDefines the password for the document file if it is protected with a password.stringoptional
regionDefines the default display format for currency and date and time when converting from Spreadsheet format to pdf. Is set using the four letter (en-US, fr-FR, etc.) language codes. The default value is en-US.stringoptional
spreadsheetLayoutDefines settings for converting the spreadsheet to pdf.objectoptional
Please note that the maximum number of pages that can be returned at once after converting a spreadsheet into pdf or image formats is no more than 1500.
spreadsheetLayout.fitToHeightSets the height of the converted area, measured in the number of pages. The default value is 0.integeroptional
spreadsheetLayout.fitToWidthSets the width of the converted area, measured in the number of pages. The default value is 0.integeroptional
spreadsheetLayout.gridLinesAllows to include grid lines to the output PDF file or not. The default value is false.booleanoptional
spreadsheetLayout.headingsAllows to include the headings to the output PDF file or not. The default value is false.booleanoptional
spreadsheetLayout.ignorePrintAreaDetermines whether to ignore the print area chosen for the spreadsheet file or not. The default value is true.booleanoptional
spreadsheetLayout.marginsSets the margins of the output PDF file.objectoptional
spreadsheetLayout.margins.bottomSets the bottom margin of the output PDF file. The default value is 19.1mm.stringoptional
spreadsheetLayout.margins.leftSets the left margin of the output PDF file. The default value is 17.8mm.stringoptional
spreadsheetLayout.margins.rightSets the right margin of the output PDF file. The default value is 17.8mm.stringoptional
spreadsheetLayout.margins.topSets the top margin of the output PDF file. The default value is 19.1mm.stringoptional
spreadsheetLayout.orientationSets the orientation of the output PDF file. May be landscape, portrait. The default value is portrait.stringoptional
spreadsheetLayout.pageSizeSets the page size of the output PDF file.objectoptional
spreadsheetLayout.pageSize.heightSets the page height of the output PDF file. The default value is 297mm.stringoptional
spreadsheetLayout.pageSize.widthSets the page width of the output PDF file. The default value is 210mm.stringoptional
spreadsheetLayout.scaleAllows to set the scale of the output PDF file. The default value is 100.integeroptional
thumbnailDefines the settings for the thumbnail when specifying the image formats (bmp, gif, jpg, png) as outputtype.objectoptional
thumbnail.aspectDefines the mode to fit the image to the height and width specifyed. Supported values:
  • 0 - stretch file to fit height and width,
  • 1 - keep the aspect for the image,
  • 2 - in this case, the width and height settings are not used. Instead of that, metric sizes of the page are converted into pixels with 96dpi. E.g., the A4 (210x297mm) page will turn out to be a picture with the 794x1123pix dimensions.
The default value is 2.
integeroptional
thumbnail.firstDefines if the thumbnails should be generated for the first page only or for all the document pages. If false, the zip archive containing thumbnails for all the pages will be created. The default value is true,booleanoptional
thumbnail.heightDefines the thumbnail height in pixels. The default value is 100.integeroptional
thumbnail.widthDefines the thumbnail width in pixels. The default value is 100.integeroptional
titleDefines the converted file name.stringoptional
tokenDefines the encrypted signature added to the Document Server config in the form of a token.stringrequired by configuration
urlDefines the absolute URL to the document to be converted. Be sure to add a token when using local links. Otherwise, an error will occur.stringrequired

* - in the tables below you can see possibility of conversion your documents into the most known file formats, where the Input format column corresponds to the values of the filetype parameter and the Output format columns correspond to the values of the outputtype parameter.

Text document file formats

Input formatOutput format
bmpdocmdocxdocxfdotmdotxepubfb2gifhtmljpgodtottpdfpdfapngrtftxt
djvu
doc
docm
docx
docxf
dot
dotm
dotx
epub
fb2
fodt
htm
html
mht
mhtml
odt
ott
oxps
pdf
rtf
stw
sxw
txt
wps
wpt
xps
xml

Spreadsheet file formats

Input formatOutput format
bmpcsvgifjpgodsotspdfpdfapngxlsmxlsxxltmxltx
csv
et
ett
fods
ods
ots
sxc
xls
xlsb
xlsm
xlsx
xlt
xltm
xltx
xml

Presentation file formats

Input formatOutput format
bmpgifjpgodpotppdfpdfapngpotmpotxppsmppsxpptmpptx
dps
dpt
fodp
odp
otp
pot
potm
potx
pps
ppsm
ppsx
ppt
pptm
pptx
sxi

Sample of JSON object sent to document conversion service used to convert the file from docx format to pdf format

  1. {
  2. "async": false,
  3. "filetype": "docx",
  4. "key": "Khirz6zTPdfd7",
  5. "outputtype": "pdf",
  6. "title": "Example Document Title.docx",
  7. "url": "https://example.com/url-to-example-document.docx"
  8. }

Where example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

Sample of JSON object sent to document conversion service used to convert the password-protected file from docx format to pdf format

  1. {
  2. "async": false,
  3. "filetype": "docx",
  4. "key": "Khirz6zTPdfd7",
  5. "outputtype": "pdf",
  6. "password": "123456",
  7. "title": "Example Document Title.docx",
  8. "url": "https://example.com/url-to-example-document.docx"
  9. }

Where example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

Sample of JSON object sent to document conversion service used to generate png thumbnail of file in docx format

  1. {
  2. "filetype": "docx",
  3. "key": "Khirz6zTPdfd7",
  4. "outputtype": "png",
  5. "thumbnail": {
  6. "aspect": 0,
  7. "first": true,
  8. "height": 150,
  9. "width": 100
  10. },
  11. "title": "Example Document Title.docx",
  12. "url": "https://example.com/url-to-example-document.docx"
  13. }

Where example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

Sample of JSON object sent to document conversion service used to convert the spreadsheet file to pdf format

  1. {
  2. "filetype": "xlsx",
  3. "key": "Khirz6zTPdfd7",
  4. "outputtype": "pdf",
  5. "region": "en-US",
  6. "spreadsheetLayout": {
  7. "ignorePrintArea": true,
  8. "orientation": "portrait",
  9. "fitToWidth": 0,
  10. "fitToHeight": 0,
  11. "scale": 100,
  12. "headings": false,
  13. "gridLines": false,
  14. "pageSize": {
  15. "width": "210mm",
  16. "height": "297mm"
  17. },
  18. "margins": {
  19. "left": "17.8mm",
  20. "right": "17.8mm",
  21. "top": "19.1mm",
  22. "bottom": "19.1mm"
  23. }
  24. },
  25. "title": "Example Document Title.docx",
  26. "url": "https://example.com/url-to-example-spreadsheet.xlsx"
  27. }

Where example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

Sample of JSON object contains the JSON Web Token sent to document conversion service used to convert the file from docx format to pdf format

  1. {
  2. "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmaWxldHlwZSI6ImRvY3giLCJrZXkiOiJLaGlyejZ6VFBkZmQ3Iiwib3V0cHV0dHlwZSI6InBkZiIsInRpdGxlIjoiRXhhbXBsZSBEb2N1bWVudCBUaXRsZS5kb2N4IiwidXJsIjoiaHR0cDovL2V4YW1wbGUuY29tL3VybC10by1leGFtcGxlLWRvY3VtZW50LmRvY3gifQ.U-YAfuuy7clWjn-xOncfJ-sxVG5DlcYn0AOzJYkoR0M"
  3. }

Where example.com is the name of the server where document manager and document storage service are installed. See the How it works section to find out more on Document Server service client-server interactions.

Response parameters and their description

The request result is returned in XML format. To receive a response in JSON format you need to specify the Accept header with the application/json value in the HTTP request (available from version 4.3). When forming the link to the resulting file, the same server name is used which was made the conversion request to.

ParameterDescriptionTypeExample
endConvertDefines if the conversion is completed or not.booleantrue
errorDefines an error occurred during the conversion. Possible error codes can be found here.integer-3
fileTypeDefines an extension of the converted file.string“docm”
fileUrlDefines the link to the converted document. This parameter will be received only when the endConvert parameter is set to true.stringhttps://documentserver/url-to-converted-document.pdf
percentDefines the percentage of the file conversion. If the endConvert parameter is set to true, the percent is equal to 100.integer100

Sample of the response in XML format

When forming the link to the resulting file, the same server name is used which was made the conversion request to.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <FileResult>
  3. <EndConvert>True</EndConvert>
  4. <FileType>docm</FileType>
  5. <FileUrl>https://documentserver/url-to-converted-document.pdf</FileUrl>
  6. <Percent>100</Percent>
  7. </FileResult>

Sample of the response in JSON format

When forming the link to the resulting file, the same server name is used which was made the conversion request to.

  1. {
  2. "endConvert": true,
  3. "fileType": "docm",
  4. "fileUrl": "https://documentserver/url-to-converted-document.pdf",
  5. "percent": 100
  6. }

Sample of the intermediate response to the asynchronous request (with the parameter async=true) in XML format

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <FileResult>
  3. <EndConvert>False</EndConvert>
  4. <FileType></FileType>
  5. <FileUrl></FileUrl>
  6. <Percent>95</Percent>
  7. </FileResult>

Sample of the intermediate response to the asynchronous request (with the parameter async=true) in JSON format

  1. {
  2. "endConvert": false,
  3. "percent": 95
  4. }

Sample of the response when an error occurred in XML format

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <FileResult>
  3. <Error>-3</Error>
  4. </FileResult>

Sample of the response when an error occurred in JSON format

  1. {
  2. "error": -3
  3. }

Possible error codes and their description

Error codeDescription
-1Unknown error.
-2Conversion timeout error.
-3Conversion error.
-4Error while downloading the document file to be converted.
-5Incorrect password.
-6Error while accessing the conversion result database.
-7Input error.
-8Invalid token.