leccionesonline
leccionesonline

Reputation: 608

global positioning an image with itext

Anybody knows if there are any special coordinates in iText to global positioning an image at the bottom right of the document?

I'm not sure it exists...

Upvotes: 0

Views: 886

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

First we need to know if you're talking about a Document that is created from scratch or about adding an Image to an existing document.

If you create a document from scratch, then the coordinate of the bottom-right depends on the page size you've used when creating the Document object. For instance: for an A4 page, the bottom right corner has x = 595 ; y = 0 (the measurements are done in 'user unit' which correspond with points by default). So if you want to position an image in the bottom right corner, you need to use img.setAbsolutePosition(595 - img.getScaledWidth(), 0); and then just use document.add(img); to add the image. DISCLAIMER: if you use a page size that differs from the default, or if you define a CropBox, you'll need to adapt the coordinates accordingly.

If you want to add an image to an existing document, you need to inspect the page size, and you need to check if there's a CropBox. You need to calculate the offset of the image based on these values. Again you can use setAbsolutePosition(), but you need to add the image to a PdfContentByte object obtained using the getOverContent() or getUnderContent() method (assuming that you're using PdfStamper).

Upvotes: 1

Related Questions