I am using page events to add a header to a pdf document.  The header
contains a PdfPTable.  I would like to add a String containing a page number
to the last row of the PdfPTable.  However, when I initialize the PdfPTable
(in setPageHeader), the page number does not exist yet -- it only exists in
the "onEndPage" method.  How can I put the page number in the PdfPTable? 
(code sample below -- if I am not posting the code properly, please let me
know how post code samples)

    public class ComplexHeader extends PdfPageEventHelper {

      private PdfPTable pdfHeaderTable;
      private float pdfHeaderPadding = 10;
      private float headerDataHeight;
        
      public ComplexHeader() {
        ; //Do nothing, just initialize the object
      }
      
      // Called from the program creating the document before any content is
added to the document;
      // Is there a way to put the page number into iHeaderTable before
passing it?  Otherwise, can I pass in a third parameter 
      // (String numberedPhrase) that can be appended to the header in
onEndPage?  If using numberedPhrase, how can I calculate the page margins 
      // here to adjust them properly?
      public void setPageHeader (PdfPTable iHeaderTable, Document document)
{
        pdfHeaderTable = new PdfPTable(iHeaderTable);
        pdfHeaderTable.setTotalWidth(document.right() - document.left());
        headerDataHeight = pdfHeaderTable.getTotalHeight();
        document.setMargins(document.leftMargin(), document.rightMargin(),
(document.topMargin() + headerDataHeight + pdfHeaderPadding),
document.bottomMargin());
      }
  
      public void onEndPage(PdfWriter writer, Document document) {
        PdfContentByte cb = writer.getDirectContent();
        pdfHeaderTable.writeSelectedRows(0, -1, document.left(),
document.top() + headerDataHeight + pdfHeaderPadding, cb);
      }
    }
-- 
View this message in context: 
http://itext-general.2136553.n4.nabble.com/Add-a-page-number-to-a-PdfPTable-tp2233494p2233494.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------

_______________________________________________
iText-questions mailing list
[email protected]
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/

Reply via email to