java中的Itext PDF操作
我需要使用 java 中的 itext lib 将 HTML 转换为 PDF。 我的输入 HTML 页面具有表格结构,并且具有单独的页眉和页脚。我已将此页面转换为 PDF ,但是由于我的 HTML 页面有一个与之关联的页脚,我试图将生成的 PDF 的页脚重新定位到特定页面的实际数据结束的位置(即,如果页面仅包含 10来自标题的数据行,然后我尝试在第 10 行之后添加页脚)。 PDFEventHelper 类帮助我添加页眉和页脚,但我对这种重定位要求感到震惊。 谁能告诉我如何处理这种情况? 有谁知道如何读取PDF页面上的空白(未写入)扇区? 提前致谢。
I have a requirement to convert a PDF from HTML using itext lib in java.
My input HTML page has a tabular structure and it has separate header and footer. I've converted this page to PDF , however as my HTML page has a footer associated with it, I'm trying to relocate footer of my generated PDF to location where actual data of a particular page ends(i.e if a page contains only 10 lines of data from header then I'm trying to add footer after 10th line). PDFEventHelper class helped me to add header and footer,but I'm getting struck with this relocation requirement.
Can anybody tell me how to deal with such scenarios??
does anyone knows how to read blank(unwritten) sectors on PDF page ??
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
传递到
onEndPage
重写中的Document
实际上是一个PdfDocument
。将参数转换为
PdfDocument
后,您可以调用PdfDocument.getVerticalPosition(true)
来确定最后一个元素的布局位置并相应地绘制页脚。请注意,这仅给出了 Y 位置,但这就是页脚真正需要的全部。传递给 getVerticalPosition 的参数称为“ensureNewLine”。我强烈怀疑您传递的内容并不重要,因为这是结束页面事件,并且任何尾随行都已被写入/完成/关闭/无论其名称如何。
The
Document
passed into youronEndPage
override is actually aPdfDocument
.Once you've cast the parameter to a
PdfDocument
, you can callPdfDocument.getVerticalPosition(true)
to determine where the last Element was laid out and draw your footer accordingly. Note that this only gives the Y position, but that's all you really need for a footer.The parameter passed to getVerticalPosition is called "ensureNewLine". I strongly suspect what you pass won't matter because this is the End Page Event, and any trailing lines will have already been written/finished/closed/whatever-its-called.