简体   繁体   English

java 中的 Itext PDF 操作

[英]Itext PDF manipulation in java

I have a requirement to convert a PDF from HTML using itext lib in java.我需要使用 Z93F725A07423F74DBB1CED00381AA4Z 中的 itext 库从 HTML 转换 PDF。 My input HTML page has a tabular structure and it has separate header and footer.我的输入 HTML 页面具有表格结构,并且具有单独的 header 和页脚。 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(ie if a page contains only 10 lines of data from header then I'm trying to add footer after 10th line).我已将此页面转换为 PDF,但是由于我的 HTML 页面有一个与之关联的页脚,我正在尝试重新定位我生成的 PDF 的页脚来自 header 的数据行,然后我尝试在第 10 行之后添加页脚)。 PDFEventHelper class helped me to add header and footer,but I'm getting struck with this relocation requirement. PDFEventHelper class 帮助我添加了 header 和页脚,但我对这个重定位要求感到震惊。 Can anybody tell me how to deal with such scenarios??谁能告诉我如何处理这种情况? does anyone knows how to read blank(unwritten) sectors on PDF page??有谁知道如何读取 PDF 页面上的空白(未写入)扇区? Thanks in advance.提前致谢。

The Document passed into your onEndPage override is actually a PdfDocument .传递给您的onEndPage覆盖的Document实际上是一个PdfDocument

Once you've cast the parameter to a PdfDocument , you can call PdfDocument.getVerticalPosition(true) to determine where the last Element was laid out and draw your footer accordingly.将参数转换为PdfDocument ,您可以调用PdfDocument.getVerticalPosition(true)来确定最后一个元素的布局位置并相应地绘制页脚。 Note that this only gives the Y position, but that's all you really need for a footer.请注意,这只给出了 Y position,但这就是您真正需要的页脚。

The parameter passed to getVerticalPosition is called "ensureNewLine".传递给 getVerticalPosition 的参数称为“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.我强烈怀疑您传递的内容无关紧要,因为这是结束页面事件,并且任何尾随行都已经被编写/完成/关闭/不管它叫什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM