Asynchronous request

Asynchronous means that the request will return immediately with a requestId (if the request passes validation), but the pdf file will be sent after a few seconds to your custom webhook.

When to use it

Asynchronous requests are useful when you want to generate a large number of pdf reports or if you don't want to block your user experience while the pdf is being generated.

You can fire off the requests and wait for your webhook endpoint to be called with the requestId.

How to use it

Send a POST request to https://api.pdforge.com/v1/html-to-pdf/async

Body params:

Name
Type
Description

html (required)

string

The HTML content you want to render

webhook (required)

string

The url of your webook

pdfParams

object

The object containing the parameters for your PDF. See all the options here.

convertToImage

boolean

If true, will return a .PNG file instead of a .PDF file (default: false)

s3_bucket

string

The id of the active s3 connection you want to store your generated file on.

(only available in the high plan)

s3_key

string

The path, including subdirectories and the filename without extension, to use when saving the render in your S3 bucket.

(only available if being stored in custom s3_bucket)

The endpoint accepts only JSON data.

It's required to send both the html and webhook parameters.

Request:

curl --location 'https://api.pdforge.com/v1/html-to-pdf/sync' \
--header 'Authorization: Bearer pdforge_api_123456789' \
--header 'Content-Type: application/json' \
--data '{
    "html": "<html>Your HTML here!</html>",
    "webhook: "https://webhook.url"
}
'

This endpoint responds with 200 OK immediately with a renderId, with the following response body:

{
    "requestId": "pdforge_request_123456789"
}

After a few seconds, the pdf file will be generated and we will send a POST to your webhook with the following body:

{
    "requestId": "pdforge_request_123456789",
    "renderStatus": "SUCCESS",
    "signedUrl": "https://pdforge-production.s3.us-east-2.amazonaws.com/..."
}

The renderStatus could be either SUCCESS or FAILED.

The response body will contain a signedUrl key which is a temporary URL pointing to the generated pdf file on our s3 bucket. If you passed a custom s3_bucket, it'll be stored there instead. This URL will expire after 1 hour.

Last updated