Learn how to use the /v1/transform/pdf
endpoint to convert HTML content to PDF.
To access the /v1/transform/pdf
endpoint, you need to authenticate using your API key. Pass your API key in the X-Api-Key
header.
You can manage your API keys in your account.
X-Api-Key: YOUR_API_KEY
The /v1/transform/pdf
endpoint accepts the following fields in the request body:
source_url
- URL to load the HTML content from (e.g., https://example.com
).source_raw
- HTML content encoded in base64.width
- The width of the PDF in inches.height
- The height of the PDF in inches.pages
- Page ranges to include in the PDF (e.g., "1, 3-5, 10-15"
).scale
- The scale of the content. Defaults to 1
. Can be a decimal (e.g., 1.5
).print_background
- true
or false
to print background graphics.landscape
- true
for landscape orientation, false
for portrait.margin
- An object defining the margins in inches. Includes the following fields:
top
bottom
left
right
Important
Either source_url
or source_raw
must be provided.
Each document conversion counts as one credit. The number of credits required for a conversion depends on the number of documents processed. For example, converting a single HTML document to PDF will consume 1 credit.
After a successful conversion, the API will return a response containing the following fields:
{
"link": "https://pdfdrift-results.s3.eu-west-1.amazonaws.com/455a83a8-2b2e-4e6b-9cbd-2405653fb5bd.pdf",
"credits": 1
}
The link
field contains a URL to download the generated PDF. This link is valid for 3 days.
Here are some examples of how to use the /v1/transform/pdf
endpoint:
POST https://pdfdrift.com/api/v1/transform/pdf
Content-Type: application/json
{
"source_url": "https://example.com"
}
POST https://pdfdrift.com/api/v1/transform/pdf
Content-Type: application/json
{
"source_raw": "PGh0bWw+PGJvZHk+VGhpcyBpcyBhIHRlc3QgUERGIGRvY3VtZW50LjwvYm9keT48L2h0bWw+"
}
POST https://pdfdrift.com/api/v1/transform/pdf
Content-Type: application/json
{
"source_url": "https://example.com",
"width": 8.5,
"height": 11,
"scale": 1.5,
"print_background": true,
"landscape": false,
"margin": {
"top": 0.5,
"bottom": 0.5,
"left": 0.5,
"right": 0.5
}
}