Gesture Callbacks in Flutter PDF Viewer (SfPdfViewer)
10 Jul 20261 minute to read
The SfPdfViewer supports the PdfGestureTapCallback 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 – This property returns the tapped position on the page in PDF coordinates. The coordinates have their origin at the top-left of the page. 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('Flutter PDF Viewer'),
),
body: SfPdfViewer.network(
'https://cdn.syncfusion.com/content/PDFViewer/flutter-succinctly.pdf',
onTap: (PdfGestureDetails details) {
print('${details.pageNumber}');
},
),
);
}