I add a bunch of stuff to a page, using a sequence of
Then I add a table that fills two columns at absolute positoins using the
column.setSimpleColumn( x[count], document.bottom(), x[count], document.top() - height - 10);
heightis set to 0. This places the table in a column that starts at the top of the document. Of course, what I'd like to do is to add the column directly below the last thing written to the document in the final
document.add()statement. If I knew the height consumed thus far on the page, I could manually enter the correct
heightvalue and things work fine.
The problem is, what gets written in the document depends on a lot of conditions, so I'd like to execute a command to tell me
how much height has been consumed thus far in the document (for the current page) so I can set
Is there a way to do this in iText so that I don't need to keep track of the heights of each individual element added to the page?
In iText 7 we add elements to the page using
After creating an element we can receive the occupied area and X and Y coordinates of it, by next way:
Paragraph p = new Paragraph("Hello World"); doc.add(p); IRenderer pRenderer = p.createRendererSubTree().setParent(doc.getRenderer()); LayoutResult pLayoutResult = pRenderer.layout(new LayoutContext(new LayoutArea(0, new Rectangle(595-72, 842-72)))); float y = pLayoutResult.getOccupiedArea().getBBox().getY(); float x = pLayoutResult.getOccupiedArea().getBBox().getX();
Click this link if you want to see how to answer this question in iText 5.