PDF documents use a coordinate space that differs from the view coordinate space used by Flutter. The PDF coordinate system has its origin in the bottom-left corner with y values increasing upward, while Flutter view coordinates have their origin in the top-left corner with y values increasing downward.

Nutrient Flutter SDK provides coordinate conversion APIs on NutrientViewController(opens in a new tab) for mapping between these two coordinate spaces on Android and iOS.

Coordinate conversion is supported on Android and iOS. It isn’t available on Web.

Converting view coordinates to PDF coordinates

convertViewPointToPdfPoint converts a point from the view coordinate space to the PDF page coordinate space. The input point is in logical pixel coordinates relative to the upper-left corner of the rendered page:

NutrientViewController? controller;
NutrientView(
documentPath: documentPath,
onViewCreated: (NutrientViewController c) {
controller = c;
},
onDocumentLoaded: (PdfDocument document) async {
final pdfPoint = await controller?.convertViewPointToPdfPoint(
0, // pageIndex (zero-based)
const Offset(150.0, 300.0),
);
print('PDF coordinates: (${pdfPoint?.dx}, ${pdfPoint?.dy})');
},
)

Converting PDF coordinates to view coordinates

convertPdfPointToViewPoint converts a point from the PDF page coordinate space to the view coordinate space. The returned Offset is in 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 guide on coordinate spaces.