Merge templates
The merge templates endpoint of our API allows you to combine multiple PDF templates into a single PDF document.
POST /api/templates/merge
Headers |
|
| Authorization* |
The
|
| Accept |
Default: application/pdf
The
|
| Content-Type |
Default: application/json
The
|
Request body |
|
| templates* |
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 merge templates endpoint. In this example, we have an invoice and a shipping label template that we want to merge into a single PDF document. 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/merge" \
-H "Content-Type: application/json" \
-H "Accept: application/pdf" \
-d '{
"templates": [
{
"id": "templateId1",
"data": {
"name": "John Doe",
"order_id": "ABC123",
"total": "$ 120.00"
}
},
{
"id": "templateId2",
"data": {
"address": "123 Main St",
"city": "New York",
"tracking_code": "XYZ789"
}
}
]
}'
Response
PDF Content
The API will respond with a PDF file containing the merged content of the specified templates. 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.
JSON Response
If the
Accept header is set to
application/json, the API will respond with a JSON object containing two keys:
status and
data. The
status key will contain the HTTP status code of the response, and the
data contains the PDF file encoded as a base64 string.
{
"status": 200,
"data": "CONTENT_OF_THE_PDF_FILE"
}
URL Response
If the
output parameter is set to
url, the API will respond with a URL to the generated PDF file.
{
"status": 200,
"data": "URL_TO_PDF_FILE"
}