简体   繁体   中英

Itext PDF manipulation in java

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(ie 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.

The Document passed into your onEndPage override is actually a 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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