WEB to PDF Rest API.

The API for converting Web Pages to PDF files.

Available converters

API Request

Parameter Description Value
Secret

Optional

String

Authentication secret (if omitted, token must be provided)

Secret
Token

Optional

String

Authentication token (if omitted, secret must be provided)

Token
Parameter Description Value
FileName

Optional

String

File name (without extension) of the converted file.

FileName
Parameter Description Value
Timeout

Optional

Integer

Conversion timeout in seconds.

Default: 300

Values: 10 .. 1200

Timeout
StoreFile

Optional

Bool

Store converted file on server.

Default: False

StoreFile
Url

Required

String

URI of a web page to convert. Must start with http:// or https://. Several URI of web pages merged with %20 (space) symbol can be passed to create one PDF. For example if http://www.google.com%20http://www.nytimes.com URI will be passed the two web pages will be merged into one PDF. If URI has special characters like ? or & they must be encoded. Also a HTML code can be submitted for conversion using this parameter.

Url
ConversionDelay

Optional

Integer

Delay in seconds before page load and PDF creation. Sometimes usefull to let web page to load in full.

Default: 0

Values: 0 .. 30

ConversionDelay
Scripts

Optional

Bool

Allow web pages to run javascript.

Default: True

Scripts
Parameter Description Value
AuthUsername

Optional

String

HTTP authentication username. Could be used if conversion web page is protected with HTTP authentication.

AuthUsername
AuthPassword

Optional

String

HTTP authentication password. Could be used if conversion web page is protected with HTTP authentication.

AuthPassword
Parameter Description Value
AdBlock

Optional

Bool

Block ads in converting page.

Default: False

AdBlock
LoadLazyContent

Optional

Bool

Load page images that loads only when they are visible.

Default: False

LoadLazyContent
CssMediaType

Optional

Collection

Use CSS media type in conversion process.

Default: screen

Values: screen, print

CssMediaType
ViewportWidth

Optional

Integer

Sets browser viewport width.

Default: 1366

Values: 0 .. 10000000

ViewportWidth
ViewportHeight

Optional

Integer

Sets browser viewport height.

Default: 768

Values: 0 .. 10000000

ViewportHeight
Background

Optional

Bool

Print web page background.

Default: True

Background
FixedElements

Optional

Collection

Change fixed elements CSS 'position' property to adapt page for conversion.

Default: fixed

Values: fixed, absolute, relative, hide

FixedElements
Zoom

Optional

Float

Set the default zoom level of webpages.

Default: 1

Values: -10.0 .. 100.0

Zoom
Parameter Description Value
PageOrientation

Optional

Collection

PDF page orientation.

Default: portrait

Values: portrait, landscape

PageOrientation
PageSize

Optional

Collection

PDF page size.

Default: letter

Values: a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, b0, b1, b2, b3, b4, b5, letter, legal, ledger

PageSize
PageWidth

Optional

Integer

Custom page width in millimeters. This option override PageSize option.

Values: 10 .. 30000

PageWidth
PageHeight

Optional

Integer

Custom page height in millimeters. This option override PageSize option.

Values: 10 .. 30000

PageHeight
Parameter Description Value
MarginTop

Optional

Integer

Set the page top margin in millimeters.

Default: 10

Values: 0 .. 500

MarginTop
MarginRight

Optional

Integer

Set the page right margin in millimeters.

Default: 10

Values: 0 .. 500

MarginRight
MarginBottom

Optional

Integer

Set the page bottom margin in millimeters.

Default: 10

Values: 0 .. 500

MarginBottom
MarginLeft

Optional

Integer

Set the page left margin in millimeters.

Default: 10

Values: 0 .. 500

MarginLeft
Parameter Description Value
PageRange

Optional

String

Set page range. Example 1-10 or 1,2,5.

Default: 1

PageRange

Snippets are autogenerated according to converter parameter choices above. Please select file in "File" or "Files" parameter before using code snippets.

Media Types

Authentication parameter (secret or token) always must be provided as a query parameter.

Request

  • application/json - JSON scheme also can be built in Code Snippets section. File data must be encoded with Base64 encoding, provided as URL or uploaded File ID. DOC to PDF scheme example:
    POST https://v2.convertapi.com/doc/to/pdf?Secret=XXX
    {
        "Parameters": [
            {
                "ConversionTime": 3,
                "Name": "File",
                "FileValue": {
                    "Name": "my_file.doc",
                    "Data": "--Base64 encoded file content--"
                }
            }
        ]
    }
    Merge PDF scheme example:
    POST https://v2.convertapi.com/pdf/to/merge?Secret=XXX
    {
        "Parameters": [
            {
                "Name": "StoreFile",
                "Value": "true"
            },
            {
                "Name": "PdfVersion",
                "Value": "1.7"
            },
            {
                "Name": "Files",
                "FileValues": [
                    {
                        "Name": "file.pdf",
                        "Data": "--Base64 encoded file content--"
                    },
                    {
                        "Url": "http://example.com/myfile.docx"
                    },
                    {
                        "Id": "13232131"
                    }
                ]
            }
        ]
    }
  • multipart/form-data - Each request parameter must be in separate part. If there is an array type parameter, index must be appended to parameter name e.g. Files[0], Files[1], Files[2] etc. DOC to PDF example:
    POST /doc/to/pdf?secret=XXXX HTTP/1.1
    Host: v2.convertapi.com
    Cache-Control: no-cache
    Content-Type: multipart/form-data; boundary=----7MA4YWxkTrZu0gW
    
    ------7MA4YWxkTrZu0gW
    Content-Disposition: form-data; name="StoreFile"
    
    true
    ------7MA4YWxkTrZu0gW
    Content-Disposition: form-data; name="File"; filename="my_file.doc"
    Content-Type: 
    
    --FILE DATA--
    ------7MA4YWxkTrZu0gW
    Content-Disposition: form-data; name="DocumentTitle"
    
    Test title
    ------7MA4YWxkTrZu0gW--
  • query parameters - Using query parameters it is possible to convert file which is accessible by URL or uploaded File ID. DOCX to PDF URL example:
    https://v2.convertapi.com/docx/to/pdf?Secret=XXX&File=http://example.com/myfile.docx&StoreFile=true
    If there is an array type parameter, index must be appended to parameter name e.g. Files[0], Files[1], Files[2] etc.

Response

Response headers and body contains this information:

  • ConversionTime - time in seconds that took to convert file. In this ammount of seconds your balance will be decreased after conversion.
  • FileName - name of converted file.
  • FileSize - converted file size in bytes.
  • FileData - converted file content.
  • FileUrl - link to converted file if "StoreFile" parameter is set to "true".

Response examples by media type:
  • application/json - response scheme can be explored in Test Request response box. Single file result example:
    {
        "ConversionTime": 2,
        "Files": [
            {
                "FileName": "my_file.pdf",
                "FileSize": 523672,
                "FileData": "--Base64 encoded file content--"
            }
        ]
    }
  • application/xml - XML scheme is analogous to JSON. Single file result example:
    <Conversion xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <ConversionTime>2</ConversionTime>
        <Files>
            <File>
                <FileName>my_file.pdf</FileName>
                <FileSize>522579</FileSize>
                <FileData>--Base64 encoded file content--</FileData>
                <Url i:nil="true" />
            </File>
        </Files>
    </Conversion>
  • multipart/mixed - each part contains converted file data or URL to the file. Single file result example:
    --43cf1475-ab15-4c6b-b5ee-e2cbcedfe92f
    ConversionTime: 3
    Content-Type: application/octet-stream
    Content-Disposition: attachment; filename="my_file.pdf"; size=8475
    
    --FILE CONTENT--
                    
    --43cf1475-ab15-4c6b-b5ee-e2cbcedfe92f--
  • application/octet-stream - response body is result file content. File name can be found in content-disposition header field. Can be used with converters that produce only one file result.

Other features

  • Converted files that are stored on convertapi.com server can be accessible for further conversion operations. This method allows conversion chaining, without increased network load. Example: conversion PDF to JPG produces as many files as there are pages in PDF file. If these files are stored on the server and links to the files are passed to ZIP converter, result will be one ZIP file with JPG files of each PDF page.
  • If ?view=true is appended to a stored conversion result file download link, file will be viewed in browser rather than downloaded. Example:
    https://v2.convertapi.com/d/HQ5TRU5Z/my_file.pdf?view=true