Gesture callbacks

11 Sep 20231 minute to read

The SfPdfViewer supports the PdfGestureCallback, to notify the touch or mouse interaction with the widget.

Tap callback

The onTap callback triggers when the user taps on the SfPdfViewer widget and the PdfGestureDetails returns the following information,

  • pageNumber – This property returns the page number on which the tap took place. The value ranges from 1 to the total number of pages in the PDF document. If the tap occurs outside any PDF page boundaries, the result will be -1.

  • pagePosition – The property returns the page’s tapped position in the PDF coordinates. The coordinates have their origin at the top-left of the page. The number of the tapped page is identified by the PageNumber property. If the tap occurs outside any PDF page boundaries, the result will be (-1, -1).

  • position – This property returns the tapped position on the PDF Viewer widget. The coordinate space starts at the top left of the widget.

The following code example illustrates how to retrieve information from the PdfGestureDetails and handle the onTap callback.

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text('Syncfusion Flutter PDF Viewer'),
    ),
    body: SfPdfViewer.network(
      'https://cdn.syncfusion.com/content/PDFViewer/flutter-succinctly.pdf',
      onTap: (PdfGestureDetails details) {
        print('${details.pageNumber}');
      },
    ),
  );
}