API Specification
The pdfg API accepts a JSON payload containing HTML content and PDF generation options.
Endpoint
POST https://api.pdfg.net/v1
Headers
Content-Type: application/json
Authorization: Bearer YOUR_API_KEY
Request Body
The request body is a JSON object with two parameters:
html(required): HTML content to be converted to PDF as a string.pdfOptions(optional): Various settings for PDF generation.preview(optional): When set to true, adds a watermark to the PDF and doesn't count towards API usage. Useful for development and testing.uploadUrl(optional): A presigned PUT URL (e.g. AWS S3). When provided, the generated PDF is uploaded directly to this URL instead of being returned in the response body.
PDF Options
The following parameters can be specified in pdfOptions:
| Parameter Name | Type | Description | Default Value |
|---|---|---|---|
displayHeaderFooter | boolean | Whether to show the header and footer | false |
footerTemplate | string | HTML template for the print footer. Has the same constraints and support for special classes as headerTemplate | "" |
format | string | Paper format. One of Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6. Takes priority over width and height when specified | "letter" |
headerTemplate | string | HTML template for the print header. Supports the following special classes: - date: Print date- title: Document title- url: Document location- pageNumber: Current page number- totalPages: Total pages | "" |
height | string | number | Sets the height of paper. You can pass in a number (pixels) or a string with a unit | - |
landscape | boolean | Whether to print in landscape orientation | false |
margin | object | Set the PDF margins (top, right, bottom, left) | undefined (no margins) |
omitBackground | boolean | Hides default white background and allows generating PDFs with transparency | false |
pageRanges | string | Paper ranges to print, e.g., '1-5, 8, 11-13' | "" (all pages) |
preferCSSPageSize | boolean | Give any CSS @page size declared in the page priority over what is declared in width/height/format options | false (scale to fit paper size) |
printBackground | boolean | Set to true to print background graphics | false |
scale | number | Scales the rendering of the web page. Amount must be between 0.1 and 2 | 1 |
width | string | number | Sets the width of paper. You can pass in a number (pixels) or a string with a unit | - |
Request Example
Here's a cURL request example with all PDF options specified:
curl --location 'https://api.pdfg.net/v1' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data '{
"html": "<h1>Hello World</h1>",
"pdfOptions": {
"displayHeaderFooter": true,
"footerTemplate": "<div style=\"text-align: center; width: 100%; font-size: 10px;\"><span class=\"pageNumber\"></span> / <span class=\"totalPages\"></span></div>",
"format": "A4",
"headerTemplate": "<div style=\"text-align: center; width: 100%; font-size: 10px;\">Sample Header</div>",
"height": "297mm",
"landscape": false,
"margin": {
"top": "20mm",
"right": "20mm",
"bottom": "20mm",
"left": "20mm"
},
"omitBackground": false,
"pageRanges": "1-5",
"preferCSSPageSize": false,
"printBackground": true,
"scale": 1,
"width": "210mm"
}
}' \
--output sample.pdf
Response
Without uploadUrl
Returns the generated PDF as binary data.
With uploadUrl
Returns an empty JSON object {} with Content-Type: application/json. The PDF has been uploaded to the provided URL.