Forum Bugs

shrink-to-fit resizes every page after large page was encountered

Tested on Prince 10 rev 7, Prince 12.5 and Prince 20190814 on windows.

In the attachments you can see a document with 'prince-shrink-to-fit' on 'auto', the body contains three tables, every table has 'page-break-after' on 'always'.
The first page contains a small table with 5 columns.
The second page contains a large table with 20 columns
The third page contains a small table with 5 columns.

With shrink-to-fit, the first page remains sized normally, the second page is resized so that it will fit onto the page, however the last page is resized the same amount as the second page, even though it has no problem fitting onto the page.

I would expect the last page to be the same size as the first page. Is there a way to fix this behaviour?

  1. sample-data.html1.5 kB
    The HTML input
  2. sample.pdf24.0 kB
    The PDF output

You can get the desired behaviour by using named pages. E.g.:

@page big_table {
    prince-shrink-to-fit: auto;
table.big {
    page: big_table;

then add class="big" to the middle table.

See for more info.

That seems to work perfectly, thanks for the help. Although I still find the behavior in my original post odd.

Did something change after which made it remember the last shrink-size and applies it to the entire document afterwards?

- Mark

Edited by mark.snijder

I also find the current behaviour a bit odd! Originally the feature was intended as a "per document" shrink-to-fit, which is useful for formatting documents that aren't sized correctly for printing. We implemented this somewhat cheaply by just measuring the width of the content up to the first break, and (if needed) shrinking the whole document based on that.

The implementation was changed to retry the sizing measurement after a forced break if there was not already a shrink factor, which explains the observations you made above. I'm not exactly sure why we made this change; we might need to revisit it.

It is perhaps worth noting that it should be a bit more efficient to use named pages as above, rather than applying shrink-to-fit to the entire document (assuming that did what you want), because only the named pages will need the extra sizing measurement.
Interesting to know the inner-workings :)

Your solution did indeed do what I wanted, we just changed the code to 'if more than x columns then give page a name' with the shrink-to-fit and landscape mode set to that page name (which is extra nice since it will only flip the large page in the document now!).

However it would still be nice of princexml to determine it automatically without 'magic numbers' where manually is specified what a good cut-off point is like we did.

Thanks for the help! I'm not sure how to close bugs here though.

Edited by mark.snijder