flutter_pdfview icon indicating copy to clipboard operation
flutter_pdfview copied to clipboard

Is there a way to get the coordinates of a tap event on a page?

Open GP4cK opened this issue 3 years ago • 6 comments

I would like to let the user add markers on the PDF. For that, I would need 2 things:

  1. Being able to listen to tap events on the PDF to get a set of coordinates X and Y
  2. Give the viewer a list of coordinates and some colors so that it can place the markers on top of the document

I understand that it may not be supported at the moment but may I have some indications on how to start if I had to implement this? Thanks a lot!

GP4cK avatar Oct 19 '20 04:10 GP4cK

Have you tried to spread out GestureDetector in Stack with PDF like this:

Stack(
  children: [
     GestureDetector(
      onLongPressStart: (touchDetails) {
        double x = touchDetails.globalPosition.dx; // touchDetails.localPosition
        // do something with coordinates
      },
    ),
    PDF(),
  ],
),`

PcolBP avatar Oct 20 '20 13:10 PcolBP

Yes, the problem is when you zoom and pan, you don't get the right coordinates...

GP4cK avatar Oct 21 '20 06:10 GP4cK

I've tried to pass ScaleGestureRecognizer and PanGestureRecognizer as gestureRecognizers but they don't seem to catch any gesture. I've asked a question on SO as this is not entirely related to the viewer itself but more to AndroidView and UiKitView

GP4cK avatar Oct 22 '20 03:10 GP4cK

@GP4cK I know it's been two years, but did you have any luck with this? I'm in a similar situation right now, and am considering disabling zoom via some overlay, and having controls for page scrolling be done via buttons.

sammusaev avatar Nov 21 '22 12:11 sammusaev

@sammusaev I ended up converting the PDF to png in the backend and use an InteractiveViewer.

GP4cK avatar Nov 21 '22 23:11 GP4cK