mPDF Manual – Paging

# Using @page

(mPDF >= 4.2)

The paged media model of CSS (http://www.w3.org/TR/1998/REC-CSS2-19980512/page.html) is used as a basis

The dimensions set when calling a new mPDF() set the Sheet size.

The Page-box size is assumed to be the same as the sheet size by default.

The page-box margins are therefore by default the left/right/top and bottom margins.

NB Page-box margins are INSIDE the page-box (unlike block elements in CSS).

## Supported CSS selectors

The CSS @page selector is partially supported in mPDF with the following properties:

### Notes

All properties except size are optional.

Three values for the \$size property set the page box to the same size as the sheet:

auto

The page box will be set to the size and orientation of the target sheet.

landscape

Overrides the target’s orientation. The page box is the same size as the target, and the longer sides are horizontal.

portrait

Overrides the target’s orientation. The page box is the same size as the target, and the shorter sides are horizontal.

NB The prefix “html_” used before the name is used to denote a header/footer defined as HTML code.

If a header/Footer name is set as _blank (or any name that hasn’t been defined) it will turn off Headers/Footers.

Crop marks indicate where the page should be cut. Cross marks (also known as register marks or registration marks) are used to align sheets.

If you have defined @page {} in the CSS, then the values for the margins will override the ones set calling a new mPDF().

IMPORTANT - if you define a @page {} but don’t specifiy margins, they will be set to the initial margin values of mPDF.

If you set a page(-box) smaller than the sheet size, the margins are increased by the difference between the page-box and sheet size - automatically centering the page-box inside the sheet.

If you change page-box orientation, the sheet orientation will follow.

Note that block-style elements - and any styling associated with it - will be terminated at a page-break.

## Pseudo-selectors

CSS pseudo-selectors :left :right and :first are recognised by mPDF and support the same properties as @page except:

• size
• margin-left
• margin-right
• odd-footer-name
• even-footer-name

Example:

Pseudo-selectors for page can change top, bottom, header and footer margins, but not left and right margins. mPDF can only cope with one set of (optionally mirrored) left/right margins.

Properties specified in a :first @page rule override those specified in :right (or :left) @page rules for the first page only

## Named @page selectors

Named pages are also supported e.g.:

You can then refer to the named page in other CSS style sheets:

&lt;div class="onitsside"&gt; will thus start a new right/odd page which will be in landscape.

## Setting a named page

You can also set the page using parameters in:

### page-break-before

The CSS property ‘page-break-before’ is useful in conjunction with a named page definition.

 page-break-before: always left right;

always

Always force a page break before the generated block element.

left

Force one or two page breaks before the generated block element so that the next page is formatted as a left/even page.

right

Force one or two page breaks before the generated block element so that the next page is formatted as a right/odd page.

So, for example, page-break-before: right is equivalent of AddPage(... 'NEXT-ODD'...)