Hi,
Using iText 5.4.0 (and previous versions) I'm having issues with very
large lines containing images as soon as they take up around 50% of the
available page height. Basically iText inserts an additional, completely
blank page before the actual line is inserted, and it adds page breaks
when there is more than enough space left on the current page.
Stepping through the source, I stumbled upon the following
implementation in PdfDocument#carriageReturn:
// If the current line is not null or empty
if (line != null && line.size() > 0) {
// we check if the end of the page is reached (bugfix by Francois
Gravel)
if (currentHeight + line.height() + leading > indentTop() -
indentBottom()) {
^^^
// if the end of the line is reached, we start a newPage which
will flush existing lines
// then move to next page but before then we need to exclude
the current one that does not fit
// After the new page we add the current line back in
PdfLine overflowLine = line;
So the leading is added to the line height, which doesn't really matter
for normal text (when both values are much smaller than the page
height), but in my case the line height might be around 300pt, the
leading around 350pt, and the page height around 700pt, so adding the
line height has quite an effect on this calculation.
I tried and removed line.height() from the equation and at least the
blank pages disappeared. A similar calculation is done in
PdfDcoument#add (see attached patch).
Daniel
Index: src/main/java/com/itextpdf/text/pdf/PdfDocument.java
===================================================================
--- src/main/java/com/itextpdf/text/pdf/PdfDocument.java (revision 5713)
+++ src/main/java/com/itextpdf/text/pdf/PdfDocument.java (working copy)
@@ -497,7 +497,7 @@
carriageReturn();
// we don't want to make orphans/widows
- if (currentHeight + line.height() + leading > indentTop() - indentBottom()) {
+ if (currentHeight + leading > indentTop() - indentBottom()) {
newPage();
}
indentation.indentLeft += paragraph.getIndentationLeft();
@@ -1159,7 +1159,7 @@
// If the current line is not null or empty
if (line != null && line.size() > 0) {
// we check if the end of the page is reached (bugfix by Francois Gravel)
- if (currentHeight + line.height() + leading > indentTop() - indentBottom()) {
+ if (currentHeight + leading > indentTop() - indentBottom()) {
// if the end of the line is reached, we start a newPage which will flush existing lines
// then move to next page but before then we need to exclude the current one that does not fit
// After the new page we add the current line back in
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php