4
Answers

How to add Page numbers,header and footer to pdf document

Hi,
I have to add header and footer to a pdf document.I am using MVC4 and rendering view to pdf document and downloading by using ITextSharp.Now I am using the below code 
 
public ActionResult DownloadPDF(string shipId)
{
var report = new ActionAsPdf("ExporttoPDF", new { shipId = shipId });
return report;
}
 
Could any one please help me how to add header and footer while downloading the pdf through code. 
Answers (4)
0
Mahesh Bodepudi

Mahesh Bodepudi

NA 90 14.1k 7y
Hi,
 
Thanks for the answers ,here I am using Rotativa library for generating the pdf report and when I rendering the view I am getting the master page related exceptions where I should not  use master page in that view.
Here is my code.
 
 return new ViewAsPdf("ExporttoPDF.aspx", viewModel)
 {
  FileName = "Report.pdf",
  CustomSwitches = "--print-media-type --header-center \"text\""
  };
 
With the above code I am not able to show any header and footer and I have to show page numbers in Header and footer.Please help on this. 
 
0
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 7y
Follow below links that may help you:
 
https://stackoverflow.com/questions/10515548/how-to-add-page-number-in-footer-in-pdf-by-itextsharp
 
https://stackoverflow.com/questions/18996323/add-header-and-footer-for-pdf-using-itextsharp
 
https://www.codeproject.com/Questions/1019714/adding-page-number-to-pdf-using-itextsharp 
0
alice yang

alice yang

NA 747 86 7y
Refer below link:
 
http://www.c-sharpcorner.com/blogs/adding-a-header-or-footer-to-pdf-in-c-sharp 
0
Nilesh Patil

Nilesh Patil

NA 3.4k 6.7k 7y
Hi 
refer this links
 
1. https://stackoverflow.com/questions/18996323/add-header-and-footer-for-pdf-using-itextsharp
 
2. https://www.codeproject.com/Questions/112064/How-to-add-Header-and-Footer-in-a-pdf-using-itexts
 
if you satisfied then accept my solution