Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 要在itextShap的最后一页上删除页脚吗_C#_Itext - Fatal编程技术网

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),因为我已经尝试过这种方法。