Java 中 iText 的多行标题

发布于 2024-10-01 19:50:18 字数 370 浏览 1 评论 0原文

我正在使用 PdfPageEventHelper 将标题添加到我的 pdf 中。我想添加一个多行标题。我知道我可以使用 ColumnText.showTextAligned 添加一行,从理论上讲,我可以采用一个字符串,使用标题的宽度将其包裹起来,然后单独添加行。此方法不会移动页面内容,并且标题会与页面上的文本重叠。有没有办法添加一个标题来换行并将内容向下移动?

在 onStartPage 事件中使用 document.add(myPhrase) 确实会向下移动内容并正确包装标题文本,但有时它会插入到不应插入的页面上(例如在最后一页的底部)。

解决这个问题的正确方法是什么?

我有“iText in Action”第二版,但我在那里找不到合适的例子。

谢谢。

I am using PdfPageEventHelper to add header to my pdf. I would like to add a multi-line header. I know that I can use ColumnText.showTextAligned to add a single line, and theoretically speaking I can take a string, wrap it using the width of the header and then add lines individually. This approach does not move the contents of the page and the header overlaps the text on the page. Is there a way to add a header that will wrap and move the content down?

Using document.add(myPhrase) in onStartPage event does move the content down and wraps header text properly, but sometimes it is inserted on pages where it should not be inserted (for example at the bottom of the very last page).

What is the proper way to address this issue?

I have "iText in Action" second edition, but I could not find a proper example there.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苦行僧 2024-10-08 19:50:18

我在 此线程。我还使用了“iText in Action”第二版第 pg 中的注释。 79 找出我的标题占用了多少空间,并使用此信息来更改页面的上边距。

I found a partial answer to my question at this thread. I also used a note in "iText in Action" second edition on pg. 79 to find out how much space my header occupied and used this information to change the top margin of the pages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文