【问题标题】:How to add header and footer in all page of pdf using iTextsharp version 5.2.0 in C#如何在 C# 中使用 iTextsharp 5.2.0 版在 pdf 的所有页面中添加页眉和页脚
【发布时间】:2012-04-28 22:36:29
【问题描述】:

我正在使用 itextsharp 创建一个 pdf 文件。我想为 pdf 文档中的每一页添加页眉和页脚。谁能告诉我该怎么做?

我使用的是 itext 5.2.0 在此,我无法找到使用 HeadeFooter 类的选项,该选项在早期版本中可用。

提前谢谢..

【问题讨论】:

标签: c# asp.net pdf-generation itextsharp


【解决方案1】:

对于 iTextSharp 版本 5+,已删除页眉/页脚属性。现在这可以由我们PageEventHandler 类来完成。虽然现在还不是很先进,但好处是现在您可以添加更多内容,而不仅仅是在页眉和页脚中添加计划文本。 Please check this link 用于在 iTextSharp 中完整锻炼页眉/页脚等。

【讨论】:

    【解决方案2】:

    请使用此代码。

    public partial class Footer : PdfPageEventHelper
    {
        public override void OnEndPage(PdfWriter writer, Document doc)
        {
           Paragraph footer= new Paragraph("THANK YOU", 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);
        }
    }
    

    请查看我的博客了解更多详情 http://gopalkaroli.blogspot.in/2011/11/how-to-add-header-and-footer-on-pdf.html

    https://gopalkaroli.wordpress.com/2011/11/12/how-to-add-header-and-footer-on-pdf-file-using-itextsharp-5-1/

    【讨论】:

      猜你喜欢
      • 2013-09-30
      • 2016-04-30
      • 2020-07-23
      • 2016-11-03
      • 1970-01-01
      • 1970-01-01
      • 2015-09-02
      相关资源
      最近更新 更多