This document describes our "Webpage to PDF" functionality (API endpoint), its associated HTTP header options, and possible error responses. See example usage here or scroll down.
Endpoint: service.headless-render-api.com
PDF Path: /pdf/$URL
Example URL:
https://service.headless-render-api.com/pdf/https://example.com/
The target $URL
is obviously part of the path, but do not re-encode or re-escape it beyond what you'd enter into a browser URL field. Both UTF-8 encoding and percent-encoding are acceptable.
Related links:
X-Prerender-Token
curl --header "X-Prerender-Token: secret-token"
A print webpage to PDF API. Try it in your browser: service.headless-render-api.com/pdf/https://example.com
cURL
curl https://service.headless-render-api.com/pdf/https://example.com/ > out.pdf
Node.js client
// npm install prerendercloud
await prerendercloud.pdf("https://example.com/", {
// Note: using noPageBreaks forces the following
// - pageRanges: "1",
// - preferCssPageSize: true
noPageBreaks: true,
printBackground: true,
// emulatedMedia options: (screen, print, braille, embossed, handheld, projection, speech, tty, tv)
emulatedMedia: "screen",
// pageRanges: "1-3",
// scale: 1.5, // Default: 1, min: 0.1, max: 2.0
// preferCssPageSize: true,
// printBackground: true,
// landscape: true,
// marginTop: 1.75,
// marginRight: 0.5,
// marginBottom: 1.75,
// marginLeft: 0.5,
// paperWidth: 8.5,
// paperHeight: 11,
});
prerender-pdf-no-page-breaks
@page {size: 8.5in 11in;}
curl --header "prerender-pdf-no-page-breaks: true"
prerender-pdf-page-ranges
curl --header "prerender-pdf-page-ranges: 1-3, 5, 7, 10-15"
prerender-pdf-scale
curl --header "prerender-pdf-scale: 1"
prerender-pdf-prefer-css-page-size
curl --header "prerender-pdf-prefer-css-page: true"
prerender-pdf-print-background
curl --header "prerender-pdf-print-background: true"
prerender-pdf-landscape
curl --header "prerender-pdf-landscape: true"
prerender-pdf-margin-top
curl --header "prerender-pdf-margin-top: 0.4"
prerender-pdf-margin-right
curl --header "prerender-pdf-margin-right: 0.4"
prerender-pdf-margin-bottom
curl --header "prerender-pdf-margin-bottom: 0.4"
prerender-pdf-margin-left
curl --header "prerender-pdf-margin-left: 0.4"
prerender-pdf-paper-width
curl --header "prerender-pdf-paper-width: 8.5"
prerender-pdf-paper-height
curl --header "prerender-pdf-paper-height: 11"
prerender-emulated-media
curl --header "Prerender-Emulated-Media: screen"
prerender-wait-extra-long
{ waitUntil: 'networkidle' }
. Useful for
pages that depend on AJAX/XHR that fire late or IPFS hosted pagescurl --header "Prerender-Wait-Extra-Long: true"
prerender-dont-wait-for-web-sockets
curl --header "prerender-dont-wait-for-web-sockets: true"
prerender-block-cookies
curl --header "prerender-block-cookies: true"
400
content-type: application/octet-stream
429
500
502
503
504