I am trying to display mutiple tables in a single PDF and display page X
of Y
at the end of each page.
X, Y should reset for every new table(Basically every new table should
start
with a new page.)
Each table can vary and span accross multiple pages.
I don't have problem while tables end in the middle of page(1 page of
multiple pages).
The problem comes when the table size matches page size.
If a table size is approximately equal to page size.
it displays page 1 of 2, when it has only one page.
For tables ending in the middle of page, if it has 3 pages, page numbers
are
displayed correctly as
1 of 3 , 2 of 3 , 3 of 3. But when table size ends at the end of page, if
there is 1 page, still it display 1 of 2.
Please note, the number of data tables is dynamic .
public class DocumentEventListener implements PdfPageEvent {
PdfTemplate m_Template;
BaseFont m_BaseFont;
PdfContentByte m_Cb;
public void onEndPage(PdfWriter writer, Document arg1) {
try {
final int page = writer.getPageNumber();
String text = "Page " + page;
m_BaseFont =
BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252,
BaseFont.NOT_EMBEDDED);
m_Cb = writer.getDirectContent();
if(m_Cb!=null){
m_Cb.beginText();
m_Cb.setFontAndSize(m_BaseFont, 8);
m_Cb.showTextAligned(PdfContentByte.ALIGN_RIGHT,text,410,20,0);
m_Cb.endText();
m_Cb.addTemplate(m_Template, 352.3f, 20);
}
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void createNewTemplate(PdfWriter arg0){
m_Cb = arg0.getDirectContent();
m_Template = m_Cb.createTemplate(85,140);
}
public void fillOutTemplate(PdfWriter arg0) {
try {
// arg0.reorderPages(null);
m_BaseFont =
BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252,
BaseFont.NOT_EMBEDDED);
m_Template.beginText();
m_Template.setFontAndSize(m_BaseFont, 8);
String text = "of " + (arg0.getPageNumber() );
m_Template.showTextAligned(PdfContentByte.ALIGN_LEFT, text, 65, 0, 0);
m_Template.endText();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block++
e.printStackTrace();
}
}
}
****************************************************
//Creating template for printing Page X of Y at
the end of page
((DocumentEventListener)
writer.getPageEvent()).createNewTemplate(writer);
document.add(dataTableX);
document.add(dataTableY);
//Filling template for printing Page X of Y at the
end of page
((DocumentEventListener)
writer.getPageEvent()).fillOutTemplate(writer);
Please let me know, if any one has faced similar problem before.
Thanks
Suresh Chennupati
------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/