Click here to Skip to main content
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 Sergey Alexandrovich Kryukov 446
1 OriginalGriff 325
2 Yogesh Kumar Tyagi 304
3 Maciej Los 235
4 Prakriti Goyal 200
0 OriginalGriff 6,417
1 Sergey Alexandrovich Kryukov 5,344
2 Maciej Los 3,434
3 Peter Leow 3,259
4 DamithSL 2,490

Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2014
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