iText - Modifying PDFWriter# Vertical Alignment manually
I've hit upon a problem using iText (java), despite hours of looking thru the docs..
Most of the code I use goes via the Document# API which tracks (via the PDFWriter instance) the current Y position. HOWEVER, we need to use the PdfContentByte par开发者_Python百科t of the API to insert some Java2d into the document, but in doing so this appears to bypass the logic which tracks verticle writes. So next time I use the Document API, it overwrites the contents of the manually inserted things. I want to mimick the behaviour of the Document# API by manually moving the cursor on N number of units (N being the height of the element inserted by the PDFContentByte API), such that when I then use the Document object again, bingo, its cursor is in the correct location. I can see that a method to obtain the cursor exists;
PdfWriter#getVerticalPosition(boolean);
But not one to set it?!
The vertical position returned by PdfWriter, is automatically handled by the writer class when you add paragraph, tables, etc to the document. If you want to add custom graphics, you have to manually handle the vertical position by saving the position of the last graphic you drawn. If you have to draw graphic at absolute position, without regard to the text added via Paragraph objects, this is simple. But if you want sinchronize the position of the graphic with high level objects (Paragraph, pdfTable and so on) you must handle iText events.
精彩评论