Customizing zoom options in our Flutter PDF viewer
This guide demonstrates how to programmatically manage the zoom scale of a PDF page.
Manual zooming
PspdfkitWidgetController
allows you to programmatically zoom to a specific scale or to an area of a PDF document page using the convenient zooming API, zoomToRect(int, Rect)
.
The
Rect
is in PDF page coordinates. For more information, refer to the web guide on coordinate space conversion.
You can also retrieve the current zoom level of a page by calling PspdfkitWidgetController#getZoomScale
. Note that this feature is currently not supported on iOS.
Zooming in to the page
To programmatically zoom in to the current page, use the zoomToRect
method, which allows you to zoom to a specific scale. If you want to apply a scale factor to the current scale (e.g. increase the page scale by 2
), you can use PdfConfiguration#defaultZoomScale
. Additionally, you can use zoomToRect(pageIndex, Rect)
to zoom in to a specific Rect
on any page (e.g. zoom in to a sentence or annotation):
// Zoom to the annotation. var boundingBox = annotationJson['boundingBox']; var lastRect = Rect.fromLTWH(boundingBox['left'], boundingBox['top'], boundingBox['width'], boundingBox['height']); _controller?.zoomToRect(18, lastRect)
zoomToRect(int, Rect)
will automatically navigate to the given page if another page is currently being viewed. There’s no need to manually switch the page.
For more information on zooming, explore the ZoomExample
inside our Catalog app.
Starting the document at a given scale
You can start a document at a predetermined scale on a specific page. Note that on Android, rotating the screen will reset the scale. The defaultZoomScale
property in PdfConfiguration
controls this behavior:
PdfConfiguration configuration = PdfConfiguration(
defaultZoomScale: 3.0f
);
Disabling zooming
To disable zooming, set the maximumZoomScale
of PdfConfiguration
to 1
. It’s important to set this value before creating the view:
val configuration = PdfConfiguration(
maximumZoomScale: 1.0f
);