Thank you, I downloaded the document through you link but it is all for
JAVA, anyway i took the example givien in chapter 5 under listing 5.20 and
converted to c#.net.When i run my application i do not find any header added
to the pdf documents. Please have a look at the code and please let me know
what i m missing here. I am also attaching c# implementation of the
TableHeader class given in the example and output i got.

Regards



Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition",
"attachment;filename=tables.pdf");
        ////Create PDF document
        Document doc = new Document(PageSize.A4.Rotate(), 15, 15, 15, 15);
        PdfWriter writer = PdfWriter.GetInstance(doc,
Response.OutputStream);

        TableHeader th = new TableHeader();
        writer.PageEvent = th;
        th.setHeader("my test header");
        Paragraph title = null;
        Chapter chapter = null;
        Section section = null;
        string strtitle = "";
        //doc.Open();
        doc.OpenDocument();
        try
        {

            strtitle = "CHAPTER 1";
            chapter = new Chapter(strtitle, 1);
            section = chapter.AddSection(strtitle);
            section.Add(new Phrase("section 1"));
            doc.Add(chapter);
            doc.NewPage();


            strtitle = "CHAPTER 2";
            chapter = new Chapter(strtitle, 2);
            section = chapter.AddSection(strtitle);
            section.Add(new Phrase("section 2"));
            doc.Add(chapter);

        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            doc.Close();
        }

On Fri, Nov 5, 2010 at 8:03 PM, 1T3XT info [via iText - General] <
ml-node+3029011-1484391504-199...@n4.nabble.com<ml-node%2b3029011-1484391504-199...@n4.nabble.com>
> wrote:

> On 5/11/2010 14:43, Malik Mohiuddin Quadri wrote:
> > Is book available as eBook on internet to buy?
>
> Yes:
> http://affiliate.manning.com/idevaffiliate.php?id=223_212
> --
> This answer is provided by 1T3XT BVBA
> http://www.1t3xt.com/ - 
> http://www.1t3xt.info<http://www.1t3xt.info/?by-user=t>
>
> ------------------------------------------------------------------------------
>
> The Next 800 Companies to Lead America's Growth: New Video Whitepaper
> David G. Thomson, author of the best-selling book "Blueprint to a
> Billion" shares his insights and actions to help propel your
> business during the next growth cycle. Listen Now!
> http://p.sf.net/sfu/SAP-dev2dev
> _______________________________________________
> iText-questions mailing list
> [hidden email] <http://user/SendEmail.jtp?type=node&node=3029011&i=0>
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> Many questions posted to this list can (and will) be answered with a
> reference to the iText book: http://www.itextpdf.com/book/
> Please check the keywords list before you ask for examples:
> http://itextpdf.com/themes/keywords.php
>
>
> ------------------------------
>  View message @
> http://itext-general.2136553.n4.nabble.com/HeaderFooter-class-tp3027962p3029011.html
> To unsubscribe from HeaderFooter class, click 
> here<http://itext-general.2136553.n4.nabble.com/template/TplServlet.jtp?tpl=unsubscribe_by_code&node=3027962&code=bWFsaWtxYWRyaUBnbWFpbC5jb218MzAyNzk2MnwxNDk4NzgyMDc0>.
>
>
>


 <http://www.emoticoncaptain.com/wp/ie.php?plg=ie&subs=gmail&elm=sign>

public class TableHeader : PdfPageEventHelper {
        /** The header text. */
        String header;
        /** The template with the total number of pages. */
        PdfTemplate total;
        
        /**
         * Allows us to change the content of the header.
         * @param header The new header String
         */
        public void setHeader(String header) {
            this.header = header;
        }

        /**
         * Creates the PdfTemplate that will hold the total number of pages.
         * @see com.itextpdf.text.pdf.PdfPageEventHelper#onOpenDocument(
         *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
         */
        public void onOpenDocument(PdfWriter writer, Document document) {
            total = writer.DirectContent.CreateTemplate(30, 16);
        }
        
        /**
         * Adds a header to every page
         * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(
         *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
         */
        public void onEndPage(PdfWriter writer, Document document) {
            PdfPTable table = new PdfPTable(3);
            try {
                
                 float[] totalwidths ={527};
                table.SetWidths(new int[]{24, 24, 2});
                table.SetTotalWidth(totalwidths);
                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));
                Image img = Image.GetInstance(total);
                PdfPCell cell = new PdfPCell(img);
                cell.Border = Rectangle.BOTTOM_BORDER;
                table.AddCell(cell);
                table.WriteSelectedRows(0, -1, 34, 803, writer.DirectContent);
            }
            catch(DocumentException de) {
                throw de; // new ExceptionConverter(de);
            }
        }
        
        /**
         * Fills out the total number of pages before the document is closed.
         * @see com.itextpdf.text.pdf.PdfPageEventHelper#onCloseDocument(
         *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
         */
        public void onCloseDocument(PdfWriter writer, Document document) {
            ColumnText.ShowTextAligned(total, Element.ALIGN_LEFT,
                    new Phrase(Convert.ToString(writer.PageNumber - 1)),
                    2, 2, 0);
        }
    }
 
-- 
View this message in context: 
http://itext-general.2136553.n4.nabble.com/HeaderFooter-class-tp3027962p3029142.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a 
Billion" shares his insights and actions to help propel your 
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to