Page Layout & Style
Properties
Size and Orientation
Page size and orientation can be changed using the CSS @page { size }
rule.
Raw CSS
react-print
Margins
Header and Footer
Header and footer components, such as defined using <PageTop>
and <PageBottom>
, live in the margin area. If the margin is too small, the header and footer may be clipped.
Margin Units
If your PDF is meant for printing, it is best advised to set the margin properties in absolute units, such as in
or cm
. Font-size relative units such as em
or rem
are not recommended, as changing the root font-size may affect the readability of content close to page edges.
Margins can be set using the CSS @page { margin }
rule.
Raw CSS
react-print
Alternate Margins
You can set different margins for various pages using page-specific layouts.
Headers and Footers
Headers and footers can be added to your documents by removing elements from the flow and placing them in the margin area. We recommend using the <PageTop>
and <PageBottom>
components to create headers and footers.
Header and footer elements appear on all subsequent pages to where they would appear in the normal flow.
This has several implications:
- If you wish to have the header and footer on all pages, you should put them at the very beginning of the document,
- You may overwrite the header and footer by creating a new header and footer later in the document flow,
- If you wish to have different headers and footers on different pages, you should use page-specific layouts.
react-print
Raw CSS
Background Graphics
You can add edge-to-edge background graphics to your document by adding background
properties to the @page
rule.
Raw CSS
react-print
Watermarks
You can add watermarks to your document by adding @prince-overlay
properties to the @page
rule.
Raw CSS
react-print
Page-Specific Layout
Page Selectors
You can use various properties to style only specific pages in your document. For example, you can set different margins for even and odd pages, or you can add a background image to the title page.
Even and odd pages
First page
Blank page
Named Pages
@page
rules apply to all pages in the document. If you wish to control aspects of a specific page, you can use named pages and apply the rules to the named page. Named pages work similarly to all other @page
selectors.
Raw CSS
react-print
You can then use the table-landscape
class to apply the landscape layout to a specific table. The table will be moved into a new page with the landscape layout.