为pdf文档中的每个页面添加页脚 [英] add footer for each page in the pdf document

查看:87
本文介绍了为pdf文档中的每个页面添加页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用itextsharp创建一个pdf文件。我想在pdf文档中为每个页面添加页脚哪个显示页脚页码如第1页,共3页。任何人都可以告诉我该怎么做?

I am creating a pdf file using itextsharp. I want to add footer for each page in the pdf document Which Display Footer Page Number Like "Page 1 of 3". Can anyone tell me how can I do this?

推荐答案

看看以下博客: ^ ]



它说:

1.创建一个类继承自 PdfPageEventHelper

2.在此类中创建表并写入页脚内容。

Have a look at the following blog: How to add header and footer on pdf file using iTextSharp 5.1[^]

It says:
1. Create a class that in inherited by PdfPageEventHelper
2. Create table in this class and write footer content.
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);
}
}



3.此后


3. After this

Document document = new Document(PageSize.A4, 50, 50, 25, 25);
var output = new FileStream(Server.MapPath("Demo.pdf"), FileMode.Create);
PdfWriter writer = PdfWriter.GetInstance(document, output);
// Open the Document for writing
document.Open();
//using footer class
writer.PageEvent = new Footer();.
Paragraph welcomeParagraph = new Paragraph("Hello, World!");
document.Add(welcomeParagraph);
document.Close();


这篇关于为pdf文档中的每个页面添加页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆