Render PDF from Template
The PDF generation endpoint of our API allows you to dynamically create PDF documents based on pre-defined templates you created.
POST /api/templates/{templateId}/pdf
Headers |
|
Authorization* |
The
|
Accept |
Default: application/pdf
The
|
Content-Type |
Default: application/json
The
|
URL parameters |
|
templateId* |
The
|
Request body |
|
data* |
The
|
output |
Default: pdf
The
Please note that the URL expires after 15 minutes and the PDF file will be deleted from our servers. |
Example Request
Here is an example of a POST request to the PDF generation endpoint. In this example, we are using the
curl
command-line tool to send a POST request to the API.
curl -X POST "https://pdf-api.io/api/templates/{templateId}/pdf" \
-H "Content-Type: application/json" \
-H "Accept: application/pdf" \
-H "Authorization: Bearer {token}"
-d '{
"data": {
"name": "John Doe",
"order_id": "ABC123",
"total": "$ 120.00",
}
}'
When using dynamic tables with a repeatable row, the "data" should contain an array of objects, where each object represents a row in the table. The keys in the objects should match the placeholders in the table row.
{
"data": {
"invoice_items": [
{ "name": "Item 1", "qty": "2", "price": "$ 120.00" },
{ "name": "Item 2", "qty": "1", "price": "$ 65.00" }
]
}
}
Response
PDF Content
The content of the response will depend on the value of the
Accept
header in the request. If the
Accept
header is set to
application/pdf
, the API will respond with binary data in the response body. If the
Accept
header is set to
application/json
, the API will respond with a JSON object containing the PDF file encoded as a base64 string.
{
"status": 200,
"data": "CONTENT_OF_PDF_FILE"
}
PDF URL
If the
output
parameter is set to
url
, the API will respond with a JSON object containing a URL to the generated PDF file. You can use this URL to download the PDF file.
{
"status": 200,
"url": "URL_TO_PDF_FILE"
}
In case of any errors during the generation process, appropriate error codes and messages will be provided in the response.