15. Shrink-to-Fit

For some documents parts of the content are too wide to fit the pages. In most cases this is caused by HTML documents containing fixed widths intended for screens, e.g. 1024px for the main container element.

While the best solution is adding a print style sheet to override the critical styles with relative widths, such content can also be shrunk automatically without changing the source document or adding specific styles.

There are two different shrink-to-fit functionalities, -ro-scale-content and setPixelsPerInchShrinkToFit. These are non-exclusive and are applied in the aforementioned order.

15.1. The property -ro-scale-content

This property must be part of the @page rule and allows the following values:

  • A percental value which is treated as a scaling factor for the content.

  • The value "none" causes no scaling.

  • The value "auto" enables the automatic scaling of the content to fit the size of the page.

For example:

@page {
    -ro-scale-content: auto;
}

This functionality scales down entire pages, which can cause gaps at the bottom of pages.

15.2. The method setPixelsPerInchShrinkToFit

For example:

pdfReactor.setPixelsPerInchShrinkToFit(true)

This method adapts the pixels per inch value used for laying out the document, i.e. it only scales lengths set as px including such set via HTML attributes. It does not cause gaps at the bottom of pages.

The pixels per inch can also be specified manually.