Click here to Skip to main content
11,641,708 members (62,600 online)
Rate this: bad
Please Sign up or sign in to vote.
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:39am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.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
//using footer class
writer.PageEvent = new Footer();.
Paragraph welcomeParagraph = new Paragraph(“Hello, World!”);
bhavesh002 at 1-Feb-13 2:51am
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
0 DamithSL 233
1 Mika Wendelius 150
2 Sergey Alexandrovich Kryukov 134
3 OriginalGriff 110
4 Afzaal Ahmad Zeeshan 89
0 Mika Wendelius 460
1 OriginalGriff 265
2 DamithSL 258
3 CPallini 169
4 Afzaal Ahmad Zeeshan 149

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100