I am trying to create a pdf with footer. I tried the following code to have footer in my pdf file.
private void AddFooter(string filephysicalpath, string documentname)
{
byte[] bytes = System.IO.File.ReadAllBytes(filephysicalpath);
Font blackFont = FontFactory.GetFont("Arial", 12, Font.NORMAL, BaseColor.BLACK);
using (MemoryStream stream = new MemoryStream())
{
PdfReader reader = new PdfReader(bytes);
using (PdfStamper stamper = new PdfStamper(reader, stream))
{
int pages = reader.NumberOfPages;
for (int i = 1; i <= pages; i++)
{
string footer = Convert.ToString(Session["Footer"]);
footer += "\n";
footer += documentname;
Phrase ph = new Phrase(footer);
Rectangle rect = new Rectangle(10f, 10f, 0);
ColumnText ct = new ColumnText(stamper.GetUnderContent(i));
ct.SetSimpleColumn(rect);
ct.AddElement(new Paragraph("line 1"));
ct.AddElement(new Paragraph("line 2"));
ct.Go();
// ColumnText.ShowTextAligned(stamper.GetUnderContent(i), Element.ALIGN_JUSTIFIED, new Phrase(ph), 8f, 5f, 0);
}
}
bytes = stream.ToArray();
}
System.IO.File.WriteAllBytes(filephysicalpath, bytes);
}
I am not getting the footer with this code.