silverLining
silverLining

Reputation: 21

Image with absolute position to position in pdf itext

So I have an image and I set its position absolute (jsf). Then the user can change the position with the drag/drop functions from primefaces. The new coordinates (left/top) are then stored in the mysql database. When the page is reloaded, the image is again absolutely positioned with the coordinates from the db. For example the image coordinates are (the page is scrollable): left:68px; top: 826.5px

--> In java I use itext and I want to place the image with the absolute values ​​from the database. I know that the 0/0 coordinates of the PDF document are bottom left. I want to use image.setAbsolutePosition() but how does the coordinates match??? They right coordinates for the pdf would be: x about 135 and y about 700 but how this fit together with the coordinates on the screen 68px/826.5px? I have already calculate around a lot but do not understand it...

I also scale the images: the original with/height on screen: 35x35 and I use: image.scaleAbsolute(25, 25);

So how does this work? thx :)

Upvotes: 2

Views: 7494

Answers (1)

Chris Haas
Chris Haas

Reputation: 55417

If you have an image whose top left corner is at {x,y} in a top-left coordinate system and you want to place it in a coordinate system that uses bottom-left for the origin and bottom-left for placement then you need to know both the height of the image and the height of the document. The {x} won't change but the new {y} should be Document.Height - {original y} - Image.Height}.

The image below shows an image that's at {50,50} in a top-left system. Once we add it to a document we need to know the document's height (800px) so that we can map. We also need to know the image's height (75px).

enter image description here

Upvotes: 4

Related Questions