PDF页脚使用iTextSharp的底部 [英] PDF footer at the bottom using iTextSharp

查看:844
本文介绍了PDF页脚使用iTextSharp的底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建使用iTextSharp的5.0.6在C#中的PDF文档。我想分别添加页眉和页脚中的OnStartPage和事件的OnEndPage每一页。

I am trying to create a pdf document in c# using iTextSharp 5.0.6. I want to add header and footer to every page in OnStartPage and OnEndPage events respectively.

在的情况下页脚的存在是页脚创建正确的所在页的结束,而我想是在页面底部的一个问题。

In case of footer there is a problem that the footer is created right where the page ends whereas I would like to be at the bottom of page.

是否有iTextSharp的指定页面高度,使页脚底部总是产生一种方式。

Is there a way in iTextSharp to specify page height so that footer is always created at the bottom.

谢谢!

推荐答案

页面的高度的总是的定义:

document.PageSize.Height // document.getPageSize().getHeight() in Java

请记住,在PDF 0,0是左下角,而你去正确的和UP协调增长。

Keep in mind that in PDF 0,0 is the lower left corner, and coordinates increase as you go right and UP.

在你需要使用绝对坐标PdfPageEvent。这听起来像你要么获得当前y从文档,或者只是绘画的东西在当前位置。不要做。

Within a PdfPageEvent you need to use absolute coordinates. It sounds like you're either getting the current Y from the document, or Just Drawing Stuff at the current location. Don't do that.

另外,如果你想使用完全相同的页脚在每一页上,可以得出一切都变成PdfTemplate,然后绘制该模板插入你想要的各种页面。

Also, if you want to use the same exact footer on every page, you can draw everything into a PdfTemplate, then draw that template into the various pages on which you want it.

PdfTemplate footerTmpl = writer.getDirectContent().createTemplate( 0, 0, pageWidth, footerHeight );

footerTmpl.setFontAndSize( someFont, someSize );
footerTmpl.setTextMatrix( x, y );
footer.showText("blah");
// etc

然后在你的 PdfPageEvent ,你可以再补充 footerTempl 在页面的底部:

Then in your PdfPageEvent, you can just add footerTempl at the bottom of your page:

 writer.getDirectContent().addTemplateSimple( footerTmpl, 0, 0 );

即使的的页脚是一样的,你可以使用这种技术来节省内存,执行时间和文件大小。

Even if most of your footer is the same, you can use this technique to save memory, execution time, and file size.

此外,如果你不想惹 PdfContentByte 绘图命令直接,你可以通过 Col​​umnText 。有标记的iText或iTextSharp的处理该类一些做题。闲逛,你会发现他们。

Furthermore, if you don't want to mess with PdfContentByte drawing commands directly, you can avoid them to some extent via ColumnText. There are several SO questions tagged with iText or iTextSharp dealing with that class. Poke around, you'll find them.

这篇关于PDF页脚使用iTextSharp的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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