Cameron Hart wrote:
The other thing was I read that to do a footer like "Page x of y" I
need to use templates, but I couldn't understand how to use templates to
acheive this. Can anyone point me at an example?

private BaseFont baseFont;


(when doc is created:)

doc = new Document(PageSize.LETTER);
// leave space for footer template:
doc.setMargins(36F, 36F, 36F, 80F);  // left, right, top, bottom


(class must extend PdfPageEventHelper:)


public void onStartPage(PdfWriter pdfWriter, Document doc) {
String s;
float widthPoint;
s = "Page " + pdfWriter.getPageNumber() + " of ";
widthPoint = baseFont.getWidthPoint(s, 10);
baseFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
contentByte = pdfWriter.getDirectContent();
if (template == null) {
template = contentByte.createTemplate(50, 50); // width, height
} contentByte.beginText();
contentByte.setFontAndSize(baseFont, 10);
contentByte.setTextMatrix(280, 40); // move to x, y relative to template
contentByte.showText(s);
contentByte.endText();
contentByte.addTemplate(template, 280 + widthPoint, 40);
}


public void onCloseDocument(PdfWriter pdfWriter, Document doc) {
 template.beginText();
 template.setFontAndSize(baseFont, 10);
 template.showText(String.valueOf(pdfWriter.getPageNumber() - 1));
 template.endText();
}

--
____________________________________________________________
Glenn Holmer                          [EMAIL PROTECTED]
Programmer/Analyst                       phone: 414.908.1809
Weyco Group, Inc.                          fax: 414.908.1601



-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to