使用iText将标题添加到pdf [英] add header to pdf using iText

查看:747
本文介绍了使用iText将标题添加到pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用iText 5.0.5为每个PDF页面添加标题。

how i can add header to each PDF page using iText 5.0.5.

推荐答案

这包含在 iText In Action第5章,第2版。代码示例都可以在线免费获取。特别是 MovieCountries1 MovieHistory2 都处理页面页眉和页脚。

This is covered in chapter 5 of iText In Action, 2nd ed. The code examples are all freely available online. In particular MovieCountries1 and MovieHistory2 both deal with page headers and footers.

归结为使用 PdfPageEvent 实现(通常派生自 PdfPageEventHelper 来减少样板)以绘制到在EndPage(或者我认为是BeginPage)事件期间页面的直接内容。

It boils down to using a PdfPageEvent implementation (usually derived from PdfPageEventHelper to cut down on boilerplate) to draw into the page's Direct Content during an EndPage (or BeginPage I suppose) event.

你必须知道你想要它们的位置,你必须使用 PdfContentByte 实例进行绘制,这样你就可以不要使用高级段落/章节/块/图像/等类。你必须在那里画画,在这里画画。 ColumnText 可以帮助一点......但仅适用于纯文本。任何甚至是非常喜欢的东西都是你自己的。

You have to know where you want them, and you have to draw using a PdfContentByte instance, so you can't use the high-level Paragraph/Chapter/Chunk/Image/etc classes. You have to draw-this-there, draw-that-here. ColumnText can help a bit... but only for Plain Text. Anything even remotely fancy and you're on your own.

这篇关于使用iText将标题添加到pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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