Convert PDF to PNG.

Convert PDFs to PNG files with Pdftools API for use in web and desktop viewing applications or as thumbnails.

1. Authenticate API calls.

Include the header X-Api-Key to properly authorize your API calls.

  • Name
    X-Api-Key
    Type
    string
    Type
    Optional
    Description

    Substitute <API-KEY-VALUE> with the value of your API key.

X-Api-Key: <API-KEY-VALUE>

2. Get upload URL.

Send the following API call to get the upload URL.

  • Name
    X-Api-Key
    Type
    string
    Type
    Optional
    Description

    Header containing your API key.

  • Name
    fileName
    Type
    string
    Type
    Optional
    Description

    The name of the file that we are going to be uploading. ex input.pdf input.png ...

Learn more about ways to upload files on the API Reference

POST
/v1/files/upload/fromLocal
curl -L -X POST 'https://api.pdf-tools.com/v1/files/upload/fromLocal' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'X-Api-Key: <API_KEY_VALUE>' \
--data-raw '{
"fileName": "input.pdf"
}' 

Response

{
    "fileId": "101be847-f838-4361-9e27-27030291a329",
    "uploadUrl": "https://pdftools-production-developer-plat..."
}

3. Upload local file.

Upload a file to a URL. You received the URL as an uploadUrl in the response of the call described in the previous section.

  • Name
    UPLOAD_URL
    Type
    string
    Type
    Optional
    Description

    uploadUrl from previous step response.

  • Name
    PATH_TO_LOCAL_FILE
    Type
    string
    Type
    Optional
    Description

    System path to the file you want to upload, ex: c:\input.pdf c:\input.png ...

If the API call is successful, you receive the HTTP 200 status code.

PUT
<UPLOAD_URL>
curl --location --request PUT '<UPLOAD_URL>' \
--header 'Content-Type: application/octet-stream' \
--data '@<PATH_TO_LOCAL_FILE>'

4. Convert PDF to PNG.

Run the conversion operation.

  • Name
    FILE_ID
    Type
    string
    Type
    Optional
    Description

    The fileId received in the response of the upload call.

Learn more about this operation on the API Reference

POST
/v1/operations/convert/pdf-to-png
curl -L -X POST 'https://api.pdf-tools.com/v1/operations/convert/pdf-to-png' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'X-Api-Key: <API_KEY_VALUE>' \
--data-raw '{
    "input": {
        "fileId": "<FILE_ID>"
    },
    "options": {
        "colorSpace": "rgb",
        "transparentBackground": true
    }
}'

Response

{
"operationId": "f8418394-73f1-4ad4-8bb2-cda3ad9ff785",
"operationType": "convertPdfToPng",
"operationStatus": "inProgress"
}

5. Get the result.

In order to get the result, you have to use the operationId from the previous response, in this endpoint.

  • Name
    API_KEY_VALUE
    Type
    string
    Type
    Optional
    Description

    Header containing your API key from step 1

  • Name
    OPERATION_ID
    Type
    string
    Type
    Optional
    Description

    The operationId from the result in step 4.

Once the operation is done processing you will be able to download the result file from outputFile.url property of the resulting object.

GET
/v1/operations/<OPERATION_ID>/result
curl -L -X GET 'https://api.pdf-tools.com/v1/operations/<OPERATION_ID>/result' \
-H 'Accept: application/json' \
-H 'X-Api-Key: <API_KEY_VALUE>'

Response

{
    "operationType": "convertPdfToPng",
    "operationStatus": "finished",
    "outputFile": {
    "fileId": "532e9577-e943-4957-9d67-d3f04b128978",
    "name": "output.zip",
    "url": "www.exampleurl/output.zip"
}

Was this page helpful?