Click here to Skip to main content
Rate this: bad
good
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
good
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.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 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
Your Filters
Interested
Ignored
     
0 Shai Vashdi 1,588
1 OriginalGriff 528
2 Manas Bhardwaj 383
3 Damith Weerasinghe 330
4 Tadit Dash 315
0 Sergey Alexandrovich Kryukov 9,575
1 OriginalGriff 6,006
2 Peter Leow 4,500
3 Maciej Los 3,540
4 Abhinav S 3,513


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