Wednesday, August 26, 2009

Itextsharp place footer at one page and at bottom

iTextSharp.text.Image footerImage = new Quote().GetFooter();

Rectangle page = document.PageSize();

PdfPTable foot = new PdfPTable(1);
foot.DefaultCell.BorderWidth = 0;
foot.DefaultCell.BorderColorBottom = new Color(255, 255, 255);

foot.AddCell(footerImage);

foot.TotalWidth = page.Width - document.LeftMargin - document.RightMargin;

foot.WriteSelectedRows(0, -1, document.LeftMargin, foot.TotalHeight - 7, writer.DirectContent);

2 comments:

-- Reedyseth -- said...

The code you posted worked for Java I guess, but I used it in C# and with a few fixed It worked the way I wanted, thanks.

Unknown said...

In case it helps, here is my C# version.

public void PlaceFooter()
{
Rectangle page = doc.PageSize;
PdfPTable EndTable = CreatePlacementTable(false, 100);
EndTable.DefaultCell.Padding = 2f;
EndTable.HorizontalAlignment = Element.ALIGN_JUSTIFIED;

//Add anything you want into this EndTable
EndTable.AddCell("This is my footer");

EndTable.TotalWidth = page.Width - doc.LeftMargin - doc.RightMargin;
EndTable.WriteSelectedRows(0, -1, doc.LeftMargin, EndTable.TotalHeight + doc.marginBottom, writer.DirectContent);
}