Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IText 2 + Flying Saucer: how to avoid that the images appears broken between two pdf's pages?

i have an html file and i'm using Itext 2 with flying Saucer to convert it to a pdf file.

The problem is that if an image starts near the page end, flying saucer render a portion of it it the end of the current page and the rest in the beginning of the next page.

How to say that i want the entire image on one page only?

like image 733
user1240273 Avatar asked Sep 16 '25 10:09

user1240273


2 Answers

You can add this to your print css:

img {
  page-break-inside: avoid;
}

The user guide (PDF) mentions it.

like image 67
Adam Avatar answered Sep 18 '25 08:09

Adam


There appears to be a bug in FlyingSaucer that is causing issues with page-break-inside: avoid.

The issue manifests when css: orphans kicks in, when a paragraph is laid out towards the end of a page and the minimum number of lines cannot be rendered on the page. Then the block box layout state machine appears to go wrong.

We have pushed a fix to a fork here: https://github.com/krokiet/flyingsaucer/tree/master

At some point we will raise a pull request to get this merged back into the main code base.

like image 24
Pylot Avatar answered Sep 18 '25 08:09

Pylot