Skip to content
Advertisement

PDFBox 2.0.9 – creating TOC with multiple pages

I’m working on PDF Toc. It generates the first page but when I have more elements I did logic to create a new page for TOC. I’m using PDF Box and that PDPageContentStream. I had to create a function to calculate how many pages I need. Then I’m creating the exact amount of pages in the list and add them to the PDF document before I start PDPageContentStream. That stream is in a loop and it’s only generating the first page. Other pages come blank. I don’t know what exactly is wrong. Here is the code:

JavaScript

Advertisement

Answer

Page 2 sets the Y offset with this code because currentYPosition is not used when i > 0

JavaScript

so your first Y offset value is negative.

Advertisement