Coordinate conversion in the Flutter PDF viewer
PDF documents and Flutter views use different coordinate spaces. The PDF coordinate system starts in the bottom-left corner, and y values increase upward. Flutter view coordinates start in the top-left corner, and y values increase downward.
Nutrient Flutter SDK provides coordinate conversion APIs on NutrientController to map between these coordinate spaces on Android and iOS. Refer to the Nutrient controller(opens in a new tab) API reference for details.
Coordinate conversion is supported on Android and iOS. It isn’t available on web.
Convert view coordinates to PDF coordinates
Use convertViewPointToPdfPoint to convert a point from the view coordinate space to the PDF page coordinate space. The input point uses logical pixel coordinates relative to the upper-left corner of the rendered page:
NutrientDocumentView( documentPath: documentPath, onControllerReady: (controller) { controller.events.documentLoaded.listen((_) async { final pdfPoint = await controller.convertViewPointToPdfPoint( 0, // `pageIndex` (zero-based). const Offset(150.0, 300.0), );
print('PDF coordinates: (${pdfPoint.dx}, ${pdfPoint.dy})'); }); },)Convert PDF coordinates to view coordinates
Use convertPdfPointToViewPoint to convert a point from the PDF page coordinate space to the view coordinate space. The returned Offset uses logical pixel coordinates relative to the upper-left corner of the rendered page.
final viewPoint = await controller.convertPdfPointToViewPoint( 0, // `pageIndex` (zero-based). const Offset(72.0, 720.0),);
print('View coordinates: (${viewPoint.dx}, ${viewPoint.dy})');For more information about PDF coordinate spaces, refer to the web coordinate spaces guide.