问题描述
您好,感谢您阅读本文。
Hello and thanks for reading this post.
我正在使用ItextSharp创建包含我数据库内容的pdf,但这不是重要部分。
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?
感谢您的时间。
推荐答案
请查看来源代码 PdfPTable
,更具体地说是 SetExtendLastRow()
方法:
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;
}
如果您希望最后一行延伸到最后一页的底部,你需要将 extendFinalRow
设置为 true
( extendLastRows 和
extendFinalRow
是 false
)。
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
).
这篇关于Itextsharp在每个pdf页面的底部制作页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!