prefer_css_page_size
parameter allows you to control whether CSS-defined page sizes take precedence over the API-specified paper size.
Overview
When rendering a webpage to PDF, there can be a conflict between the page size specified in the API request (via thesize
parameter) and any page size defined in the document’s CSS using @page
rules. The prefer_css_page_size
parameter determines which of these takes precedence.
Parameter details
Controls whether CSS-defined page sizes take precedence over the API-specified paper size
Usage
Behavior
true
: CSS page size defined in@page
rules takes precedence over thesize
parameter. Content will be rendered using the dimensions specified in CSS.false
: Thesize
parameter takes precedence over any CSS-defined page size. Content will be scaled to fit the specified paper size.
Use cases
This parameter is particularly useful for:-
CSS-driven layouts: When your HTML content includes specific
@page
size rules that are essential to the layout design. - Consistent sizing across sources: When you want to ensure all documents use the same paper size regardless of their CSS settings.
- Web-to-print workflows: When converting web content that already has print-specific CSS rules that should be respected.