gpt4 book ai didi

c# - 如何在 C# 中使用 iTextsharp 5.2.0 版在 pdf 的所有页面中添加页眉和页脚

转载 作者:行者123 更新时间:2023-12-03 20:33:11 25 4
gpt4 key购买 nike

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

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

提前致谢..

最佳答案

请使用此代码。

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/

关于c# - 如何在 C# 中使用 iTextsharp 5.2.0 版在 pdf 的所有页面中添加页眉和页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10193761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com