Hello,
I generate a document with a table divided in two parts because of page
break. My problem is the content of the table on the second page is
shifted compared with the table borders. I know the problem comes from
the header of the document that is added after the document opening.
When I add the header before opening the document, I do not have the
problem but I don't want header on the first page.
Here is my code:
public static void main(final String[] args) throws DocumentException,
FileNotFoundException {
final Document document = new Document(PageSize.A4, 50, 50, 50, 50);
PdfWriter.getInstance(document, new FileOutputStream(new
File("file.pdf")));
document.open();
// header
final HeaderFooter header = new HeaderFooter(new Phrase("My
project"), false);
header.setAlignment(Element.ALIGN_CENTER);
header.disableBorderSide(Rectangle.TOP);
document.setHeader(header);
addALotOfText(document);
final Table table = new Table(2, 3);
table.setWidth(100);
table.setWidths(new float[]{20, 80});
table.setPadding(5);
table.addCell("one");
table.addCell("two");
table.addCell("three");
table.addCell("four");
table.addCell("five");
table.addCell("six");
document.add(table);
document.close();
}
private static void addALotOfText(final Document document) throws
DocumentException {
final String string = "jfdqsmfjd kslq jfdks fjdksqfdqm disfkdq
dksq dksmq fjkdq";
final Phrase content = new Phrase(string);
for (int i = 0; i < 56; i++) {
content.add(string);
}
document.add(content);
}
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Do you like iText?
Buy the iText book: http://www.1t3xt.com/docs/book.php
Or leave a tip: https://tipit.to/itexttipjar