I am using PDFTron to scan document and extract annotations information in some custom format. And I have problem with Ellipse
and Square
annotations.
For mentioned custom format, I need width
and height
of square (which can be rectangle). All annotations can be rotated. For rotated rectangle I am able to get bounding box using square.GetVisibleContentBox()
and rotation angle using suchh approach:
var appearance = square.GetAppearance();
var matrixApp = appearance.FindObj("Matrix");
var matrixObject = new Matrix2D(matrixApp.GetAt(0).GetNumber(), matrixApp.GetAt(1).GetNumber(),
matrixApp.GetAt(2).GetNumber(), matrixApp.GetAt(3).GetNumber(), matrixApp.GetAt(4).GetNumber(),
matrixApp.GetAt(5).GetNumber());
RotationAngle = GetRotationFromMatrix(matrixObject);
The same approach I use in case of rotated Ellipse
annotation (I need semi-major and semi-minor axes for Ellipse
). But how can I get Rectangle
width and height, or Ellipse
axes from bounding box and rotation? I have tried simple math in case of rectangle, using this post. But it does not work with 45 degree rotation. And I have no idea how to retrieve Ellipse
axes.
I have opened pdfDoc and found this for rotated Circle
annotation:
endstream
endobj
497 0 obj<</Subj(Ellipse)/Type/Annot/P 477 0 R/F 4/C[1 0 0]/CreationDate(D:20180130093056+03'00')/T(User-PC)/Subtype/Circle/M(D:20180130093101+03'00')/AP<</N 499 0 R>>/RD[0.5 0.5 0.5 0.5]/Rect[75.96057 481.4219 511.1196 824.4295]/NM(BNJOBSFLFNHJWWZE)/Rotation 30>>
endobj
498 0 obj[497 0 R]
endobj
499 0 obj<</Type/XObject/Subtype/Form/FormType 1/BBox[88.18503 573.4521 498.8952 732.3994]/Resources<</ProcSet[/PDF]>>/Matrix[0.8660253 -0.5000002 0.5000002 0.8660253 -363.0966 -247.1763]/Filter/FlateDecode/Length 116>>
stream
Pay attention to obj<</Type/XObject/Subtype/Form/FormType 1/BBox
string. This BBox
is original Ellipse
bounding box (without rotation). I have checked this. If I have not rotated BBox I can get axes of ellipse
and dimensions of Rectangle
. But how to retrieve this XObject
for annotation?
To make a summary. I need to retrieve real dimensions of Rectangle
and Circle
. It is hard to do using simple math. I have found out, that original bounding boxes are saved in pdf, but I do not know how to get this information from Annot
object. Or maybe you will give me another approach to get dimensions?
EDIT You can download sample file here