The new css parameter adds your own stylesheet to the page before the PDF is generated, so you can hide or restyle parts of a page you can't edit.
Set css to a stylesheet to add it to the page before the PDF is generated. It is for pages you can't change: a URL, or an HTML file exported from another tool. Hide a cookie banner or a chat widget, change fonts, add page breaks, or fix a layout that doesn't print well.
curl --fail --show-error --output page.pdf --request POST \
--url https://api.html2pdf.app/v1/generate \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <your-api-key>' \
--data '{
"html": "https://example.com",
"css": "#cookie-banner { display: none !important; }"
}'You can also try it in the playground, under Custom CSS.
How it works
!important, still wins; add !important to yours to override it.@import, web fonts and background images work, and what they load is waited for before the PDF is generated.html and for URLs that return a web page, and a page's Content Security Policy does not block it.lazyLoad and singlePage see the page with your styles applied.Things to know
headerTemplate and footerTemplate with inline styles inside them.iframe) on the page.If only the first screen of a page ends up in the PDF, the page probably scrolls its content inside a panel of its own. A few lines of CSS let that panel grow to its full height; see When only the first screen is in the PDF.
See Custom CSS, Parameters and Troubleshooting in the documentation.