logo

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.

PDF Options

The following parameters can be specified in pdfOptions:

Parameter NameTypeDescriptionDefault Value
displayHeaderFooterbooleanWhether to show the header and footerfalse
footerTemplatestringHTML template for the print footer. Has the same constraints and support for special classes as headerTemplate""
formatstringPaper format. One of Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6. Takes priority over width and height when specified"letter"
headerTemplatestringHTML 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
""
heightstring | numberSets the height of paper. You can pass in a number (pixels) or a string with a unit-
landscapebooleanWhether to print in landscape orientationfalse
marginobjectSet the PDF margins (top, right, bottom, left)undefined (no margins)
omitBackgroundbooleanHides default white background and allows generating PDFs with transparencyfalse
pageRangesstringPaper ranges to print, e.g., '1-5, 8, 11-13'"" (all pages)
preferCSSPageSizebooleanGive any CSS @page size declared in the page priority over what is declared in width/height/format optionsfalse (scale to fit paper size)
printBackgroundbooleanSet to true to print background graphicsfalse
scalenumberScales the rendering of the web page. Amount must be between 0.1 and 21
widthstring | numberSets 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

Returns the generated PDF as binary data.