Click here to Skip to main content
15,905,683 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello all,

I am sending autogenerated mail through my application in which I have to attach PDF
file to that mail. I am generation this file dynamically.
But I m unable to add footer in this PDF.

Please reply.
My code is as follows
HtmlForm form = new HtmlForm();
       form.Controls.Add(Grdpick);
       StringWriter sw = new StringWriter();
       HtmlTextWriter hTextWriter = new HtmlTextWriter(sw);
       form.Controls[0].RenderControl(hTextWriter);
       string html = sw.ToString();
       Document Doc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);

       PdfWriter.GetInstance(Doc, new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\pickslip\\pickslip-" + profno + ".pdf", FileMode.Create));

       Doc.Open();

       Chunk chunk1 = new Chunk("Trident Services Pvt. Ltd. \n\n", FontFactory.GetFont("Verdana", 20));
       Paragraph p1 = new Paragraph();
       p1.Alignment = Element.ALIGN_CENTER;
       p1.Add(chunk1);
       string datenow = convertdate.changeformatDate(DateTime.Now);
       Chunk chunk2 = new Chunk(" Pick Slip No : " + profno + "                                                                       Date :" + datenow + " \n", FontFactory.GetFont("Verdana", 10));
       Paragraph p2 = new Paragraph();
       p2.Alignment = Element.ALIGN_LEFT;
       p2.Add(chunk2);
       //
       //Chunk chunk4 = new Chunk(" Date :" + datenow + " \n", FontFactory.GetFont("Verdana", 10));
       //Paragraph p4 = new Paragraph();
       //p4.Alignment = Element.ALIGN_RIGHT;
       //p4.Add(chunk4);

       Chunk chunk3 = new Chunk(" Customer : " + partyname + " \n  ESN : " + ESN + "                                                                       Branch : " + Session["BrnName"].ToString() + "\n", FontFactory.GetFont("Verdana", 10));
       Paragraph p3 = new Paragraph();
       p3.Alignment = Element.ALIGN_LEFT;
       p3.Add(chunk3);

       Doc.Add(p1);
       Doc.Add(p2);
       Doc.Add(p3);

     //  Doc.Add(p5);
    //  Doc.Footer  = new HeaderFooter(footerphrase, footerphrase);
    //  Doc.Add(footerphrase);
       System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(new StringReader(html));
       HtmlParser.Parse(Doc, xmlReader);
       Doc.Close();
       string Path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\pickslip\\pickslip-" + profno + ".pdf";
Posted
Updated 30-May-11 23:07pm
v2

1 solution

If ur using iTextSharp dll then u can use
C++
OnEndPage

event of PDF.

see this

http://www.mazsoft.com/blog/post/2008/04/30/Code-sample-for-using-iTextSharp-PDF-library.aspx[^]
 
Share this answer
 
Comments
Sweetu deshpande 31-May-11 5:22am    
Thanks for reply,

but I am not able to use it in my code.
Ashishmau 31-May-11 7:35am    
To add Header and Footer u have to use pdf PageEvent. Without using it,i don't think it's possible.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900