Click here to Skip to main content
Sign Up to vote bad
good
See more: WPF
I am creating a pdf file using itextsharp. I want to add footer for each page in the pdf document Which Display Footer Page Number Like "Page 1 of 3". Can anyone tell me how can I do this?
Posted 31 Jan '13 - 1:39


1 solution

Have a look at the following blog: How to add header and footer on pdf file using iTextSharp 5.1[^]
 
It says:
1. Create a class that in inherited by PdfPageEventHelper
2. Create table in this class and write footer content.
public partial class Footer : PdfPageEventHelper
{
public override void OnEndPage(PdfWriter writer, Document doc)
{
Paragraph footer= new Paragraph(“THANK YOU”, FontFactory.GetFont(FontFactory.TIMES, 10, iTextSharp.text.Font.NORMAL));
footer.Alignment = Element.ALIGN_RIGHT;
PdfPTable footerTbl = new PdfPTable(1);
footerTbl.TotalWidth = 300;
footerTbl.HorizontalAlignment = Element.ALIGN_CENTER;
PdfPCell cell = new PdfPCell(footer);
cell.Border = 0;
cell.PaddingLeft = 10;
footerTbl.AddCell(cell);
footerTbl.WriteSelectedRows(0, -1, 415, 30, writer.DirectContent);
}
}
3. After this
Document document = new Document(PageSize.A4, 50, 50, 25, 25);
var output = new FileStream(Server.MapPath(“Demo.pdf”), FileMode.Create);
PdfWriter writer = PdfWriter.GetInstance(document, output);
// Open the Document for writing
document.Open();
//using footer class
writer.PageEvent = new Footer();.
Paragraph welcomeParagraph = new Paragraph(“Hello, World!”);
document.Add(welcomeParagraph);
document.Close();
  Permalink  
Comments
bhavesh002 - 1 Feb '13 - 2:51
Thanks For Giving Useful Solution i try to apply this solution and apply successfully and get footer but i wan to a page number in place of word "ThankYou" i need to Paging Like "Page 1 of 1" same as in word document footerpager control so any modification at that place to get paging like this ???

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 228
1 Ron Beyer 220
2 Mahesh Bailwal 215
3 Rohan Leuva 210
4 Sergey Alexandrovich Kryukov 162
0 Sergey Alexandrovich Kryukov 8,548
1 OriginalGriff 6,819
2 CPallini 3,648
3 Rohan Leuva 2,933
4 Maciej Los 2,288


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid