Hi all,
I observed a strange behaviour in
the iText library.
I have previously some code similar
to this:
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("Chap0101.pdf"));
document.open();
document.add(new Paragraph("Hello World"));
Table tbl1 = new Table();
tbl1.setOffset(0);
…. // Fill table
document.add(tbl1);
Table tbl2= new Table();
tbl2.setOffset(0);
…. // Fill table
document.add(tbl2);
document.close();
and got
certain vertical separation between the two tables.
Now, I
modify the previous code by inserting a blank page at the beginning:
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("Chap0101.pdf"));
document.open();
document.add(new Paragraph("
")); <------------------- Added line
document.newPage();
document.add(new Paragraph("Hello World"));
Table tbl1 = new Table();
tbl1.setOffset(0);
…. // Fill table
document.add(tbl1);
Table tbl2= new Table();
tbl2.setOffset(0);
…. // Fill table
document.add(tbl2);
document.close();
Suprisingly,
the distance between tbl1 and tbl2 increases a lot.
After
investigating a bit, I discovered that there is a variable called
PdfDocument.leading, whose initial value is 0, that governs magically the
spacing between tables (see PdfDocuemnt.carriageReturn()),
apart from the user controlled table offset (that I set explicitly to 0).
This
variable gets some value when a Paragraph is added.
I don't
see logical to have the separation between tables vary when a paragraph is
added, unless there is something I haven't taken into account. It's an undocumented side effect, that
has costed a lot of debugging to know what is happening.
What do
you think?
--------
David