HTML to PDF API

This html to pdf converter converts web pages to pdfs using the Google Chromium engine via it's DevTools Protocol.



Usage

GET /test (test PDF generation from sample HTML)

POST /generate (public API endpoint)

Content-Type: application/json

eg.
{
    "apiKey": "your unique API key",
    "html": "<h1>Sample h1 HTML for conversion</h1>"
}


Request Options

Parameter Type Description
apiKey string Required (authorization).
url string Required if no html. The url of the webpage to convert to pdf
html string Required if no url. The html to convert to pdf
scale string Optional. Scale of the webpage rendering. Defaults to 1. Scale amount must be between 0.1 and 2
displayHeaderFooter boolean Optional. Display header and footer. Defaults to false
headerTemplate string Optional. HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them: date, title, url, pageNumber, totalPages
footerTemplate string Optional. HTML template for the print footer. Should use the same format as the headerTemplate
printBackground boolean Optional. Print background graphics. Defaults to true
landscape boolean Optional. Paper orientation. Defaults to false
pageRanges string Optional. Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages
format string Optional. Paper format. If set, takes priority over width or height options. Defaults to 'Letter'
width integer Optional. Paper width, accepts values labeled with units
height integer Optional. Paper height, accepts values labeled with units
margin.top integer Optional. Top margin, accepts values labeled with units
margin.right integer Optional. Right margin, accepts values labeled with units
margin.bottom integer Optional. Bottom margin, accepts values labeled with units
margin.left integer Optional. Left margin, accepts values labeled with units
preferCSSPageSize boolean Optional. Give any CSS @page size declared in the page priority over what is declared in width and height or format options. Defaults to false, which will scale the content to fit the paper size


Response

If your POST request was successful then the pdf will be returned with HTTP success code 200.

Otherwise, the response will be in JSON format with an HTTP error code eg.

{
    "success": false,
    "errors": [
        {
            "msg": "Must provide either url or html",
            "param": "url_html",
            "location": "body"
        }
    ]
}