We would like to write the total page count into a PdfPTable at the
bottom of each page. To do this we used a PdfTemplate (see code below).
The problem is that the template placeholder is created but there is no
text in it.
Any help welcome!
public void onGenericTag(PdfWriter pdfWriter, Document document,
Rectangle rectangle, String string) {
if (string.startsWith("NUMPAGES")) {
IReportText field = m_Generator.getFromNumPageMap(string) ;
PdfContentByte cb = pdfWriter.getDirectContent();
PdfTemplate tpl = cb.createTemplate(0, 0);
cb.addTemplate(tpl, rectangle.left(), rectangle.bottom());
APdfTemplate pdftpl = new APdfTemplate(tpl,field);
m_Templates.add(pdftpl);
}
}
public void onCloseDocument(PdfWriter pdfWriter, Document document)
{
for (int i = 0; i < m_Templates.size(); i++) {
APdfTemplate tplObj = m_Templates.get(i);
PdfTemplate tpl = tplObj.getTemplate();
IReportText reportText = tplObj.getIReportTextObj();
BaseFont font =
m_FontTypeHelper.convertFont(reportText.GetFontName(),
reportText.GetFontSize(), reportText.GetFontColor(),
reportText.GetFormat(), m_ContextConnector).getBaseFont();
String text = "" + (pdfWriter.getPageNumber() - 1);
float fontSize = (float) reportText.GetFontSize();
float textSize = font.getWidthPoint(text, fontSize);
try {
tpl.beginText();
tpl.setWidth(textSize);
tpl.setHeight(fontSize);
tpl.setFontAndSize(font, fontSize);
tpl.setTextMatrix(0, 0);
tpl.showText(text);
tpl.endText();
} catch (Exception e) {
e.printStackTrace();
}
}
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/