How to create an annotation in WebViewer over the images from the original PDF?

23 views
Skip to first unread message

Ryan - PDFNet Developer

unread,
Dec 14, 2016, 2:39:43 PM12/14/16
to PDFTron WebViewer

Question: I want to store the location of all images in a PDF, and then use that to track when a user clicks on an image in Universal (XOD) WebViewer. However, I am having issues with translating between the two formats, and get the rectangle in the wrong location. Answer: The following shows what information you need to store, and how to translate a rectangle from PDF to XOD coordinates. PDFNet SDK side Start with the ElementReader sample code and class

PDF.Rect bbox = image_element.GetBBox();
x1
= bbox.x1;
y1
= bbox.y1;
x2
= bbox.x2;
y2
= bbox.y2;
element_page
= page_num;

Store above values in your database WebViewer side
var p1 = doc.GetXODCoordinates(element_page, x1, y1);
var p2 = doc.GetXODCoordinates(element_page, x2, y2);
var rect = new Annotations.Rect(p1.x, p1.y, p2.x, p2.y);
rect
.normalize(); // make sure x1/y1 is top left corner, and height/width is positive

rect variable now contains the location of the image in WebViewer's XOD page coordinates, where 0,0 is the top left corner of the current page. So you could create an annotation over that location.
new_annot.setRect(rect);


Reply all
Reply to author
Forward
0 new messages