FInd The (x1,y1) and (x2,y2) values of a text when the text is rotated (90, 270) degree in the PDF page (PDF BOX)

154 views Asked by At

Hi I have an Use case to find the (x1, y1) (x2, Y2) values of the text in a page when the text is rotated 90 and 180 degree.

I am able to find these values when the text is at 0 degrees and 180 degrees.

So the idea is to use the PDStreamengine class from the PDFBOX and overriding the method from the same class and using them to find the x1,y1,x2,y2 values ,

For the above code i am getting the values properly when the text is 0 and 180 degree.

for the following pdf

i.e when the text is 0 degree (x1 =31 , y1 =726 , x2 =122 , y2 = 744 )

when the text is 180 degree (x1 = 122, y1 = 744, x2 = 31, y2 = 726)

i am getting the above values.

but when i rotate the text to 90 degree, Rotated text PDF,I am getting the values as (x1 =22 , y1 =660 , x2 =22 y2 = 740)

Here we can see Both the x1 and X2 Values are same.

how can we Find the X1 and X2 values of a text when it is rotated 90 degree and 270 Degree ?

I got above mentioned values by using the following code snippet

I have also thought of using the TextPosition "printWord" method so, will that be a solution find the x1,y1,x2,y2 values.

x1 = Double.valueOf(text.getYDirAdj());
y1 = Double.valueOf(text.getXDirAdj());
x2 = x1 - text.getHeight();
y2 = y1 + text.getWidth();

And any code snippet with the example will be helpfull.

Thanks Tejas

0

There are 0 answers