PDF Annotation size and position with regards to screen

Good day,

Could you please let me know if it is possible to get an annotation's
size (i.e. width and height) and position with regards to the screen
size in Android. I have tried using Rect but it seems it's dimensions
are specific to the PDF. These dimensions do not seem to change when
you zoom or change page orientation.

I am trying to locate youtube annotations and then overlay them with a
view that has the youtube video embedded. However, I am not able to
overlay the video directly on top of the annotation because the Rect
dimensions do not correspond to the screen. I would like to get the
annotation dimensions as well as relative position w.r.t. screen, i.e.
the left and top margins.

Can you also let me know how I can identify both pages when screen
layout is in Landscape and page presentation mode is set to FACING. In
this mode the viewer displays two pdf pages at once therefore I am not
able to get all the annotaions for both pages on
mPDFView.setPageChangeListener... onPageChange().

Your co-operation is greatly appreciated.

Regards,
Tino

Hi Tino,

You can get the bounding box (bbox) of an annotation using the following code snippet:

pdftron.PDF.Rect r = annot.getRect();

pdftron.PDF.Rect bbox = new pdftron.PDF.Rect();

bbox.set((float)r.getX1(), (float)r.getY1(), (float)r.getX2(), (float)r.getY2());

Note that the bbox is specified in page space, which is independent of how the document is viewed.

Now that you know a point in page space, you can use PDFViewCtrl.convPagePtToClientPt() to convert it to client space (the viewing region of PDFViewCtrl). Suppose (x, y) is in client space, then (a, b) is in
PDFViewCtrl Canvas space, where a = x+PDFViewCtrl.getScrollX() and b = y+PDFViewCtrl.getScrollY(). With (a, b) available, you can easily add a child view to PDFViewCtrl. If you simply want to overlay
another widget on top of PDFViewCtrl in screen space, you can first compute PDFViewCtrl’s location in screen space using getLocationOnScreen() and suppose it is (s, t). Then (s+x, t+y) would be the upper-left corner of the widget that you want to overlay upon PDFViewCtrl.

When in FACING mode, PDFViewCtrl displays two pages at a time and PDFViewCtrl.getCurrentPage() will give you the page that occupies more client space. Regardless, with one page number available from the two pages, you should be able to find the other page number easily and then find all the annotations.

Regards,
Frank Liu

Hi,

Thanks a lot for the response.

However, how do i track the size of the annotation relative to the screen. It seems as if I am getting the same annotation size regardless of zoom, page orientation, etc.

If my page is in landscape, the pages and annotations are much smaller because the app defaults to FACING. The anntation size remains the same nonetheless.

Regards,
Tino

Hi,

I managed to get the screen size using the client points but I am only getting the width and X co-ordinate correctly.

The height and the Y coordinate for the screen position are not accurate.

Regards,
Tino

Hi,

Sorry to bother you so much. The problem was that I was confusing the 2 Y coordinates, Y1 and Y2.

I was using Y1 instead of Y2 to get to top left corner of the annotation.

Thanks for pointing me in the right direction.

Regards,
Tino

Hi Tino,

Not problem. I am glad to hear it works out. Yes, since PDF page space’s origin is at the lower-left corner and the Y-axis goes up and the client/screen space has its origin at the upper-left corner and the Y-axis goes down. The “upper-left” corner of the annotation in page space should be ( r.getX1(), r.getY2() ).

Regards,

Frank Liu

Hi,

How does the PDF know of zoom (multitouch pinch zoom) and how does it know of PDF movements, i.e. motion events.

Is there a listener that I can monitor?

Regards,
Tino

HI Tino,

Do you mean “How does PDFViewCtrl know of zoom…”? PDFViewCtrl provides various event feedbacks to users and the best way to listen to them is through the PDFViewCtrl.ToolManager and PDFViewCtrl.Tool interface. There is detailed explanation in the following thread:

https://groups.google.com/group/pdfnet-sdk/browse_thread/thread/5a011633d3920a2d/0c1ac717b0f3a99b?lnk=gst&q=android+tool#0c1ac717b0f3a99b

You should also be able to find more information from the SDK’s documentation.

Best Regards,
Frank Liu