Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you track the location of PDPageContentStream's text output?
    primarykey
    data
    text
    <p>I am using Java to write output to a <code>PDDocument</code>, then appending that document to an existing one before serving it to the client.</p> <p>Most of it is working well. I only have a small problem trying to handle content overflow while writing to that <code>PDDocument</code>. I want to keep track of where text is being inserted into the document so that when the "cursor" so to speak goes past a certain point, I'll create a new page, add it to the document, create a new content stream, and continue as normal.</p> <p>Here is some code that shows what I'd like to do:</p> <pre><code>// big try block PDDocument doc = new PDDocument(); PDPage page = new PDPage(); doc.addPage(page); PDPageContentStream content = new PDPageContentStream(doc, page); int fontSize = 12; content.beginText(); content.setFont(...); content.moveTextPositionByAmount(margin, pageHeight-margin); for ( each element in a collection of values ) { content.moveTextPositionByAmount(0, -fontSize); // only moves down in document // at this point, check if past the end of page, if so add a new page if (content.getTextYPosition(...) &lt; margin) { // wishful thinking, doesn't exist content.endText(); content.close(); page = new PDPage(); doc.addPage(page); content = new PDPageContentStream(doc, page); content.beginText(); content.setFont(...); content.moveTextPositionByAmount(margin, pageHeight-(margin+fontSize)); } content.drawString(...); } content.endText(); content.close(); </code></pre> <p>The important bit is the <code>content.getTextYPosition()</code>. It doesn't actually exist, but I'm sure <code>PDPageContentStream</code> must be keeping track of a similar value. Is there any way to access this value?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload