Hi,
I have a pdf where on each page I display a portion of a table and a footer
with page 1 out of numPages.
The page numbers are working correctly, however the table is not displaying
correctly. I'm not sure what I did wrong but I have a feeling it has
something to do with the ContentByte. I used examples given on your website
to get this far and I'm sure I just have something wrong. Here is my code
below.
Table Writing Code:
for (int i =0 l; i < numTableSlices; i++) {
template = cb.createTemplate(width + 5, documentHeight + 6);
datatable.writeSelectedRows(0, -1, 0, 1, 2, documentHeight, template);
datatable.writeSelectedRows(0, -1, rowStart, rowEnd, 2,
documentHeight-datatable.getHeaderHeight(), template);
Image img = Image.getInstance(template);
img.scaleToFit(document.getPageSize().width() - document.leftMargin() -
document.rightMargin(), HEIGHT);
img.setAlignment(Element.ALIGN_TOP);
PdfPCell cell = new PdfPCell(img);
cell.setBorderWidth(0);
PdfPTable table = new PdfPTable(1);
table.addCell(cell);
table.setWidthPercentage(100);
document.add(table);
document.newPage();
}
onOpenDocument code
tp1 = writer.getDirectContent().createTemplate(100, 100);
onCloseDocument code
tp1.beginText();
tp1.setFontAndSize(BaseFont.createFont("Helvetica", BaseFont.WINANSI,
false), 7);
tp1.setTextMatrix(0, 0);
tp1.showText("" + (writer.getPageNumber() - 1));
tp1.endText();
onEndPage code:
float adjust = BaseFont.createFont("Helvetica", BaseFont.WINANSI,
false).getWidthPoint("0", 7);
float textSize = BaseFont.createFont("Helvetica", BaseFont.WINANSI,
false).getWidthPoint(text, 7);
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
String text = "Page " + writer.getPageNumber() + " of ";
cb.beginText();
cb.setFontAndSize(BaseFont.createFont("Helvetica", BaseFont.WINANSI, false),
7);
cb.setTextMatrix(document.right()- textSize - adjust, document.bottom() -
9);
cb.showText(text);
cb.endText();
cb.addTemplate(tp1, document.right() - adjust, document.bottom() - 9);
cb.saveState();
What happening is on the first page the table displays correctly with the
page numbers at the bottom, the 2nd page displays the first line of code I
have for datatable.writeSelectedRows has the page numbers at the bottom and
then goes to another page. Then on the 3rd page the table is correct except
it should be on the 2nd page. I'm not sure what's causing the even pages to
only display the first line of code for writeSelectedRows and I was hoping
you would be able to help me.
Thank you,
Heather
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/