Configuring your PDF
H2P supports PDF configuration options using the same structure as Puppeteer.
You can pass these options in the options
field of your POST request to customize how your PDF is generated.
This allows full control over layout, margins, format, headers, footers, and more.
Example: POST Request with PDF Options
curl --location --request POST 'http://localhost:3000/print' \
--header 'Content-Type: application/json' \
--output ExampleFileWithPdfOptions.pdf \
--data-raw '{
"title": "ExampleRoute",
"html": "<html><body><h1>My first Heading</h1><p>My first paragraph.</p></body></html>",
"options": {
"margin": {
"top": "100px",
"right": "100px",
"left": "100px"
}
}
}'
Supported PDF Options
The list below is based on Puppeteer’s official page.pdf()
options.
format
Sets the paper format. Possible values: A4
, A3
, A5
, Legal
, Letter
, etc.
"format": "A4"
You can also set custom sizes using width
and height
.
width
and height
Use these to define custom page size (e.g. 8.5in
, 21cm
, 100mm
, 800px
).
"width": "8.5in",
"height": "11in"
margin
Controls the page margins. Units like px
, in
, cm
, and mm
are supported.
"margin": {
"top": "35px",
"right": "35px",
"bottom": "35px",
"left": "35px"
}
scale
Adjusts the scale of the webpage rendering. Accepts a float value between 0.1
and 2
.
"scale": 0.8
printBackground
Prints background graphics (images and colors). Defaults to false
.
"printBackground": true
landscape
Switches between portrait (false
) and landscape (true
) orientation.
"landscape": true
displayHeaderFooter
, headerTemplate
, footerTemplate
Adds custom headers and footers using HTML templates.
Requires displayHeaderFooter
to be true
.
"displayHeaderFooter": true,
"headerTemplate": "<span class='title'></span>",
"footerTemplate": "<span class='pageNumber'></span>/<span class='totalPages'></span>"
preferCSSPageSize
If true
, uses the @page
size from CSS. Defaults to false
.
"preferCSSPageSize": true
Notes
- Not all Puppeteer options are relevant for every use case.
- For full details and advanced customization, visit the official docs:
https://devdocs.io/puppeteer/index#pagepdfoptions