C# 要在itextShap的最后一页上删除页脚吗
实际上,我在页脚部分添加了一些文本,如“下一页继续…”。但我希望在最后一页上删除页脚。 这里有一些截图来描述更多关于我的问题。多谢各位C# 要在itextShap的最后一页上删除页脚吗,c#,itext,C#,Itext,实际上,我在页脚部分添加了一些文本,如“下一页继续…”。但我希望在最后一页上删除页脚。 这里有一些截图来描述更多关于我的问题。多谢各位 public partial class Footer : PdfPageEventHelper { public override void OnEndPage(PdfWriter writer, iTextSharp.text.Document doc) { Paragra
public partial class Footer : PdfPageEventHelper
{
public override void OnEndPage(PdfWriter writer, iTextSharp.text.Document doc)
{
Paragraph footer = new Paragraph("Continued on next page..", FontFactory.GetFont(FontFactory.TIMES, 10, iTextSharp.text.Font.NORMAL));
footer.Alignment = Element.ALIGN_RIGHT;
PdfPTable footerTbl = new PdfPTable(1);
footerTbl.TotalWidth = 300;
footerTbl.HorizontalAlignment = Element.ALIGN_CENTER;
PdfPCell cell = new PdfPCell(footer);
cell.Border = 0;
cell.PaddingLeft = 10;
footerTbl.AddCell(cell);
if (writer.PageNumber - 1 != writer.CurrentPageNumber)
{
footerTbl.WriteSelectedRows(0, -1, 415, 30, writer.DirectContent);
}
}
}
向
Footer
类添加一个标志,只要标志具有原始值,就只添加页脚字符串。当您将最后一段内容添加到文档中时,请在关闭该文档之前翻转该标志
在关闭文档
的过程中,即更改标志后,您的最后一个文档页面将被最终确定(并调用其OnEndPage
)
例如:
public partial class Footer : PdfPageEventHelper
{
public override void OnEndPage(PdfWriter writer, iTextSharp.text.Document doc)
{
if (lastPage)
return;
Paragraph footer = new Paragraph("Continued on next page..", FontFactory.GetFont(FontFactory.TIMES, 10, iTextSharp.text.Font.NORMAL));
footer.Alignment = Element.ALIGN_RIGHT;
PdfPTable footerTbl = new PdfPTable(1);
footerTbl.TotalWidth = 300;
footerTbl.HorizontalAlignment = Element.ALIGN_CENTER;
PdfPCell cell = new PdfPCell(footer);
cell.Border = 0;
cell.PaddingLeft = 10;
footerTbl.AddCell(cell);
footerTbl.WriteSelectedRows(0, -1, 415, 30, writer.DirectContent);
}
public bool lastPage = false;
}
这样使用:
Document document = ...;
PdfWriter writer = PdfWriter.GetInstance(document, ...);
Footer footer = new Footer();
writer.PageEvent = footer;
document.Open();
[... add content to document ...]
footer.lastPage = true;
document.Close();
尝试使用writer.PageCount或doc.PageCount查看当前页面是否不等于it@Shehab我必须说,我们只能设置它的值(writer.PageCount或doc.PageCount),因为我已经尝试过这种方法。