Reputation: 27051
Hello and thanks for reading this post.
I'm using ItextSharp to create a pdf with content from my database but thats not the important part.
My footer stick the bottom of every page except the last page because there might not be enought content to "push" it down.
Document ResultPDF = new Document(iTextSharp.text.PageSize.A4, 25, 10, 20, 30);
PdfWriter Write = PdfWriter.GetInstance(ResultPDF, new FileStream(Server.MapPath("~") + "/PDF/" + fileName, FileMode.Create));
ResultPDF.Open();
PdfPTable Headtable = new PdfPTable(7);
Headtable.TotalWidth = 525f;
Headtable.LockedWidth = true;
Headtable.HeaderRows = 5;
Headtable.FooterRows = 2;
Headtable.KeepTogether = true;
.....
PdfPCell Footer = new PdfPCell(new Phrase(" ")) { Colspan = 7, UseVariableBorders = true, BorderColorTop = BaseColor.BLACK, BorderColorLeft = BaseColor.WHITE, BorderColorBottom = BaseColor.WHITE, BorderColorRight = BaseColor.WHITE };
PdfPCell Footer2 = new PdfPCell(new Phrase(Session["Surveyname"].ToString() + " - " + DateTime.Now.Date.ToString("dd-MM-yyyy") + " - " + email, smallText)) { Colspan = 6 };
PdfPCell Footer3 = new PdfPCell(new Phrase("", smallText)) { Colspan = 1, HorizontalAlignment = 1 };
Headtable.AddCell(Footer);
Headtable.AddCell(Footer2);
Headtable.AddCell(Footer3);
How can I make sure that my footer stay at the bottom of every page no matter what?
Thanks for your time.
Upvotes: 0
Views: 2495
Reputation: 77606
Please take a look at the source code of PdfPTable
, more specifically at the SetExtendLastRow()
method:
/**
* When set the last row on every page will be extended to fill
* all the remaining space to the bottom boundary; except maybe the
* final row.
*
* @param extendLastRows true to extend the last row on each page; false otherwise
* @param extendFinalRow false if you don't want to extend the final row of the complete table
* @since iText 5.0.0
*/
public void SetExtendLastRow(bool extendLastRows, bool extendFinalRow) {
extendLastRow[0] = extendLastRows;
extendLastRow[1] = extendFinalRow;
}
If you want the last row to extend to the bottom of the last page, you need to set extendFinalRow
to true
(the default for extendLastRows
and extendFinalRow
is false
).
Upvotes: 1