How to add footer in existing pdf -iTextSharp
I have been trying to figure out if it is possible to add a footer to an existing PDF document. Every example I have seen is for adding a footer to a document that has just been created using PDFWriter as opposed to getting a document using PDFReader and then adding a footer to it. Does anyone know of a way that a footer can be added to an existing PDF? Thanks.
Manav PandyaPosted Jan 9, 2018, 4:00 AM
Sagar Pandurang KapPosted Jan 8, 2018, 5:23 AM
hong diPosted Jan 8, 2014, 10:14 PM
" Have a look at chapter 6 of iText in Action, 2nd edition, especially at subsection 6.4.1: Concatenating and splitting PDF documents.
Listing 6.22, ConcatenateStamp.java, shows you how you should create a PDF from copies of pages (in your case: all pages) of multiple other PDFs; the sample additionally adds a new "Page X of Y" footer; this demonstrates how you can add content at given positions on the pages while merging the source files.
"
The answer is from http://stackoverflow.com/questions/13465657/itext-add-content-to-the-bottom-of-an-existing-page
Ring ZhongPosted Dec 23, 2013, 2:30 AM
Maybe it cannot be implemented directly, here is a kind of method to help draw the footer in existing pdf file. Of course, it need to use another component but not iTextSharp, it's Spire.PDF. Try the code below,
private static void DrawPageNumber(PdfPageCollection section, PdfMargins margin, int startNumber, int pageCount)
{
foreach (PdfPageBase page in section)
{
page.Canvas.SetTransparency(0.5f);
PdfBrush brush = PdfBrushes.Black;
PdfPen pen = new PdfPen(brush, 0.75f);
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold), true);
PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right);
format.MeasureTrailingSpaces = true;
float space = font.Height * 0.75f;
float x = margin.Left;
float width = page.Canvas.ClientSize.Width - margin.Left - margin.Right;
float y = page.Canvas.ClientSize.Height - margin.Bottom + space;
page.Canvas.DrawLine(pen, x, y, x + width, y);
y = y + 1;
String numberLabel
= String.Format("{0} of {1}", startNumber++, pageCount);
page.Canvas.DrawString(numberLabel, font, brush, x + width, y, format);
page.Canvas.SetTransparency(1);
}
}
article:
http://www.e-iceblue.com/Knowledgebase/Spire.PDF/Program-Guide/Add-PDF-Footer.html
Praveen NPosted Dec 22, 2013, 11:49 PM
Thanks & Regards,
Praveen Nelge