How to get co-ordinates related to pdfdoc when i tap on the document?

Product:PDFTron Android SDK

Product Version: demo

Please give a brief summary of your issue:how to get co-ordinates related to pdfdoc where i tap on the document?
(Think of this as an email subject)

Please describe your issue and provide steps to reproduce it:
I would like to add custom annotation where i tap on the document.
How could i get rect points with respect to pdfdoc by using i can add the annotation ?
(The more descriptive your answer, the faster we are able to help you)

Please provide a link to a minimal sample where the issue is reproducible:

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:


Hi Monaj,

Thanks for contacting us about this question.
The guide below gives a better understanding of coordinates in PDFTron SDK:

Also, you can use convScreenPtToPagePt method to get coordinates:,%20java.lang.String)

Could you please give it a try?

Best regards,

Hi sbazzaz,

Thanks for the reply. I have tried with convScreenPtToPagePt method to get doc co-ordinated for annotation with respect to page. Looks like, the co-ordinates are not accurate. It means, it’s not accurate with the tapping point.

Although while zooming, the annotation is not anchoring to assigned co-ordinate. The Annotation position is moving. I have attached one recording please have a look here WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free.

I have used my code:

override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
e?.let {
val pointArray =
mPdfViewCtrl!!.convScreenPtToPagePt(it.x.toDouble(), it.y.toDouble())
createCustomAnnotation(mPdfDoc!!, pointArray)
return true
private fun createCustomAnnotation(doc: PDFDoc, arr: DoubleArray) {

val txt = Text.create(doc, Point(arr[0], arr[1]))

Please let me know, if i am missing anything for expected implementation
Thank you.

Hi Manoj,

To help us better understand the issue and better assist you,
could you please send us the PDF file that you were zooming on the screen recording?

Best regards,

Hi sbazzaz,

I observed, this is happening with all pdf what i have used in my sample app. I have attached those files, please have a look.

Thank you.
test_pins.pdf (259.2 KB)
___Surfacing Markup.pdf (326.0 KB)

Hi Manoj,

Could you please send us the pdf in your screen recording with the sticky note?
The pdf with the sticky note helps us for more investigation.

Best regards,

Hi ,

I have attached both the pdf before save note annotation & after save note annotation. After save annotation, there is no movement of annotation position but before save annotation if i zoom the pdf doc then the annotation position is not pointing to constant co-ordinate.
after_save_annotation.pdf (292.2 KB)
test_pins.pdf (259.2 KB)


I have reviewed the video and tested your provided code, it seems to be shifting on zoom because the alignment of the sticky note icon is anchored towards the top left.

Could you clarify what you would expect to see in this scenario?


Best Regards,

Hi Ama,

Thanks for the reply & review.

My app requirement is ,
I will show the custom annotation which size & position (co-ordinates w.r.t page) will not change on zooming. I do not want to save the annotation in pdf just wanted to render.

Is there any possibility to make size & position of annotation constant in document while rendering?

Thank you.


We will need to investigate further to see if it’s possible to do this for Sticky Notes annotations, an alternative solution for now is to use a CustomRelativeLayout, which will stay consistent with the document, even when zooming. You can follow example set here to see how it is done:

 CustomRelativeLayout overlay = new CustomRelativeLayout(context);
            overlay.setAnnot(pdfViewCtrl, annot, pageNum);
            linkedOverlayMap.put(annotObjNum, overlay);

Here is a video of it in action:

Best Regards,


Thanks for the reply. I have tried with this CustomRelativeLayout with sticky note as set its annotation. CustomRelativeLayout is adjusting the position and size automatically while zooming document.
But, the view is not draggable by-default. So, I made it draggable using touch event. I found the view is coming to its original position even after dragging to new position. I have attached a video plz look into this.

My app is looking for few features if i use customRelative layout.

  1. After dragging the view, the view position should be drag end position as like sticky note behaviour from attached video.
  2. We are setting annotation with this view like

val overlay = CustomPin(requireContext())
overlay.setAnnot(mPdfViewCtrl, annot, pageNum).

Is there any need to set Annotation here? Are we using co-ordinates of annotation to positioning CustomRelativeLayout view over PdfViewCntrl ?

  1. What is the correct method to set/get position of CustomRelativeLayout w.r.t pdfdoc?


We are looking to purchase licence of PDFTron. Before that, we are checking few app requirement feasibilities.
Your input will help us more.

Thank you.


  1. The reason it is reset to the original point is because of #2, it is reseting the new coordinates back to the annotation’s original x and y coordinates

  2. setAnnot() should not be required, you should use setPagePosition()

  3. You should use setPagePosition to properly position the CustomRelativeLayout, the x,y positions are based off the bottom left of the page

Can you please give this a try?



Hi Andrew,

Thanks for the reply. I have removed setAnnot() & using setPagePosition() like
private fun addCustomViewWithAnnotation(pointArray:DoubleArray) {
val overlay = CustomRelativeLayout(requireContext(), mPdfViewCtrl!!, pointArray[0],pointArray[1],1)
overlay.background = resources.getDrawable(R.drawable.ic_issue_pin)
val param = RelativeLayout.LayoutParams(100, 100)
overlay.layoutParams = param

I observed,

  1. The view position is still not updating with dragged new position.
  2. The co-ordinate of CustomRelativeLayout is not exact with touch point of PdfDocument. It seems the touch point is near to left-bottom of CustomRelativeLayout view.

I have attached video pls look into this.

Plz add some input/suggestion if i have done some wrong implementation.

The behaviour in the video looks correct, bottom left is the point specified by the setPagePosition API. You will need to adjust it yourself (calculate the center) if you want to add the view at the center of your touch point.

As for moving, you will need to re-adjust the page position based on your touch point so the view knows that its position has changed. So you want to setPagePosition again onUp based on the new location. Please keep in mind, setPagePosition always takes the bottom left point, so you need to adjust the number accordingly.

Could you please give it a try?



Thanks for the information. Surely, I will try.

Hi ,

As per the suggestion, I have tried to set co-ordinates of CustomRelativeLayout view using setPagePosition() while creating view & moving the view.


  1. As per Documentation, “When PDFViewCtrl is scrolling or zooming, CustomRelativeLayout will adjust position and size automatically according to the [app:zoomWithParent] attribute.” but i found the view is moving from its pinning point when i do zoom in. How could we restrict the position while zooming?

  2. When i try to add customview when the document is zoomed in, the view is not adding as per the touch point. Is there any method to set co-ordinate while zooming? ( or ) How do we calculate pagePt from screenPt while document is zoomed in?

I have attached recording for reference & source code has been shared before . Plz have a look & add some input/suggestions.

  1. While zooming , the view is anchored at bottom left corner in page space, so the behaviour in the video looks correct to me, if you need to anchor at center, the best approach is to create your own custom relative layout extend the PDFTron version, then based on the original source code, override methods and change the calculation to anchor center instead. (onMeasure is where the calculation happens)

  2. Can you please post the exact code (or a runnable sample) of how you are calculating the page point? If you are using convert from screen to page point, it should handle zoom automatically, this is how all other annotation type works. When you zoomed in, you can still draw on the canvas same as not zoomed in.



As suggested, I am using CustomRelativeLayout view only to create customview in pdf.
I have shared running sample source code. Please have a look.

For my app, very important requirement is the position of customrelativelayout view w.r.t pdf document should be always constant ( before drag the view ) even on zooming in/out as mentioned document but it is not helping me out.
Other issue i have mentioned on above comment How to get co-ordinates related to pdfdoc when i tap on the document? - #18 by Manoj.

Thank you.

Hi Manoj, customrelativelayout maintains the position anchor at bottom left corner, is your requirement anchor at center? Please elaborate the requirement clearly. Also, regarding your question on #18, did you see my response here How to get co-ordinates related to pdfdoc when i tap on the document? - #19 by Shirley_Gong?