The @Page Rule
Setting the Page Size
If you do not set the size, Oxygen PDF Chemistry uses portrait US-LETTER with margins of 1in.
@page
rule like this:
@page {
size: us-letter;
}
The page
sizes can be selected by name, for example, A4, A3, US-LEGAL (these are
case insensitive), or if you are planning to print on a non-standard sheet, you can specify
the width and height:
@page {
size: 5in 7in;
}
You can also specify the page orientation using the portrait
or
landscape
keywords.
@page {
size: A3 landscape;
}
You can use the @page
rule multiple times and the properties will merge as
in ordinary CSS element styling rules.
Using Page Selectors to Style the Blank, Left, Right, First, and Last Pages
There are cases where you need to have different page settings depending on the position of the page in the printed material.
@page :left {
border-right: 0.5in solid yellow;
}
@page :right {
border-left: 0.5in solid yellow;
}
The :first
and :last
selectors are used to style the
first and last page from a sequence of pages.
@page :first,:last {
border-top: 5pt solid yellow;
}
The :blank
selector is used to style the blank pages that appear as a
result of forced page breaks.
Using Named Pages
In the examples above, the default page settings were changed.
Suppose that you need to put a particular <table>
element on a landscape
page. The example below defines a named page table-landscape-page
that
switches the orientation to landscape. Then, to maximize the space available to the table,
the margin is reduced for this page. Also, the A4 size defined by the default
@page
rule is inherited by the named page.
@page {
size: A4;
margin: 1in;
}
@page table-landscape-page {
size: landscape;
margin: 0.5in;
}
table {
page: table-landscape-page;
}
Also, Oxygen PDF Chemistry allows you to break a sequence of elements that have the same page in different page groups. A simple example is a set of chapter elements where you need to apply specific formatting for the first page from each chapter.
<chapter/>...</chapter><chapter/>...</chapter><chapter/>...</chapter>
The CSS would be:
@chapter {
...
}
@chapter:first {
background-color:yellow;
}
chapter {
page: chapter;
}
But this is not enough. According to the W3C specification, all chapters that have the same
page will be merged in a single page group (sequence), and the first selector will apply
only on the first page from the first chapter. Therefore, you need to use the
-oxy-page-group
property on each of the chapter elements.
@chapter {
...
}
@chapter:first {
background-color:yellow;
}
chapter {
-oxy-page-group:start;
page: chapter;
}
The accepted values for the -oxy-page-group
property are:
- start - Forces the creation of a new page group (sequence) even if the page before the element has the same name. The W3C specification algorithm (https://www.w3.org/TR/css3-page/#using-named-pages) would merge the current element with the open page sequence.
- auto - Uses the W3C algorithm normally.