Anybody knows how to do that?
I spent a lot of time on that but could not figure out...

I know how to create a table but do not know how to put it into the header.

Here is my code:

create pdf code:
_event e = new _event();
        pw.PageEvent = e;
        e.OnStartPage(pw, document);
        e.OnEndPage(pw, document);
        e.OnOpenDocument(pw, document);
        e.OnCloseDocument(pw, document);


event:
public class _event : PdfPageEventHelper
{
//on start event will add logo.jpg on header. no problem.
    public override void OnStartPage(PdfWriter writer, Document document)
    {  iTextSharp.text.Image imghead =
iTextSharp.text.Image.GetInstance("C:/MyWorks/logo80.jpg");
        imghead.SetAbsolutePosition(0, 0);
        PdfContentByte cbhead = writer.DirectContent;
        PdfTemplate tp = cbhead.CreateTemplate(600, 250);
        tp.AddImage(imghead);
        cbhead.AddTemplate(tp, 0, 715);
        Phrase headPhraseImg = new Phrase(cbhead + "",
FontFactory.GetFont(FontFactory.TIMES_ROMAN, 7,
iTextSharp.text.Font.NORMAL));
        Header header = new Header("test", "test");
        base.OnStartPage(writer, document);

        //not sure how to add a table into the header.
    }

//following code were taken from the itext in action book. But it does not
work. The footer won't show. do not know why.
string header;
    PdfTemplate total;
    public void setHeader(string header)
    {
        this.header = header;
    }
    public void OnOpenDocument(PdfWriter writer, Document document)
    {
        total = writer.DirectContent.CreateTemplate(300, 160);
        base.OnOpenDocument(writer, document);
    }
    public void OnEndPage(PdfWriter writer, Document document)
    {
        PdfPTable table = new PdfPTable(3);

        table.SetWidths(new int[] { 24, 24, 3 });
        table.SetTotalWidth(new float[] { 50 });
        table.LockedWidth = true;
        table.DefaultCell.FixedHeight = 20;
        table.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
        table.AddCell(header);
        table.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
        table.AddCell(string.Format("Page %d of", writer.PageNumber));
        PdfPCell cell = new
PdfPCell(iTextSharp.text.Image.GetInstance(total));
        cell.Border = Rectangle.BOTTOM_BORDER;
        table.AddCell(cell);
        table.WriteSelectedRows(0, -1, 34, 700, writer.DirectContent);

        base.OnEndPage(writer, document);


    }
    public void OnCloseDocument(PdfWriter writer, Document document)
    {
        ColumnText.ShowTextAligned(total, Element.ALIGN_LEFT,
            new Phrase(writer.PageNumber.ToString()), 2, 2, 0);
        base.OnCloseDocument(writer, document);
    }
}
-- 
---------------------------
Michelle
------------------------------------------------------------------------------

_______________________________________________
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/

Reply via email to