That is excatly what I do, but header and text overlaps. The code is below:
public class Test extends PdfPageEventHelper { Document document = null; PdfWriter writer = null; void openDocument() throws DocumentException, IOException { document = new Document(PageSize.A4.rotate()); writer = PdfWriter.getInstance(document, new FileOutputStream( "/iText/out.pdf")); writer.setPageEvent(this); document.open(); } void closeDocument() { document.close(); } void addStatementHeader() throws DocumentException, IOException { PdfPTable header = new PdfPTable(1); header.setTotalWidth(770); header.setLockedWidth(true); header.setHorizontalAlignment(Element.ALIGN_CENTER); header.addCell(new PdfPCell(new Phrase("ROW 1"))); header.addCell(new PdfPCell(new Phrase("ROW 2"))); PdfContentByte cb = writer.getDirectContent(); header.writeSelectedRows(0, -1, 36, 559, cb); } public void onEndPage(PdfWriter writer, Document document) { try { addStatementHeader(); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); return; } } public void addContents() throws DocumentException { for (int i=0; i < 50; i++) { document.add(new Paragraph(String.valueOf(i) + " Hello" )); } } public static void main(String[] args) { Test app = new Test(); try { app.openDocument(); app.addContents(); app.closeDocument(); } catch (Exception e) { System.out.println("Exception " + e.getMessage()); } } } |------------> | From: | |------------> >----------------------------------------------------------------------------------------------------------------------------------------| |1T3XT info <i...@1t3xt.info> | >----------------------------------------------------------------------------------------------------------------------------------------| |------------> | To: | |------------> >----------------------------------------------------------------------------------------------------------------------------------------| |Post all your questions about iText here <itext-questions@lists.sourceforge.net> | >----------------------------------------------------------------------------------------------------------------------------------------| |------------> | Date: | |------------> >----------------------------------------------------------------------------------------------------------------------------------------| |06/21/2010 01:23 PM | >----------------------------------------------------------------------------------------------------------------------------------------| |------------> | Subject: | |------------> >----------------------------------------------------------------------------------------------------------------------------------------| |Re: [iText-questions] Displaying a table as page header | >----------------------------------------------------------------------------------------------------------------------------------------| alex.broyt...@instinet.com wrote: > Hi, I need to display a table as a header on every page of my document. > I tried to use onEndPage() event for that, but table overlaps with the > document text on every page. If a header would have been a phrase, then > ColumnText.showTextAligned() would do the trick, but how to do that in > case of a table ? Any advise? The counterpart of showTextAligned() for tables is writeSelectedRows(). -- This answer is provided by 1T3XT BVBA http://www.1t3xt.com/ - http://www.1t3xt.info ------------------------------------------------------------------------------ ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo _______________________________________________ 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/ ***************************************************************** <<<Disclaimer>>> In compliance with applicable rules and regulations, Instinet reviews and archives incoming and outgoing email communications, copies of which may be produced at the request of regulators. This message is intended only for the personal and confidential use of the recipients named above. If the reader of this email is not the intended recipient, you have received this email in error and any review, dissemination, distribution or copying is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and permanently delete the copy you received. Instinet accepts no liability for any content contained in the email, or any errors or omissions arising as a result of email transmission. Any opinions contained in this email constitute the sender's best judgment at this time and are subject to change without notice. Instinet does not make recommendations of a particular security and the information contained in this email should not be considered as a recommendation, an offer or a solicitation of an offer to buy and sell securities. *****************************************************************
<<inline: graycol.gif>>
<<inline: ecblank.gif>>
------------------------------------------------------------------------------ ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________ 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/