您好,感谢您阅读本文。
我正在使用ItextSharp创建一个包含数据库内容的pdf,但这不是重要的部分。
我的页脚粘贴在除最后一页之外的每个页面的底部,因为可能没有内容可以“推”下来。
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);
如何确保我的页脚无论如何都停留在每个页面的底部?
感谢您的时间。
答案 0 :(得分:1)
请查看PdfPTable
的源代码,更具体地说,请参阅SetExtendLastRow()
方法:
/**
* 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;
}
如果您希望最后一行延伸到最后一页的底部,则需要将extendFinalRow
设置为true
(extendLastRows
和extendFinalRow
的默认值为false
)。