Customize Zooming Options in Our iOS Viewer
This guide shows how to programmatically manage the zoom scale of a PDF page.
Manual Zooming
You can use PDFDocumentViewController.zoom(toPDFRect:forPageAt:animated:)
(opens in a new tab) to zoom to a specific rect inside a page of the current document.
This method’s rect needs to be specified in PDF coordinates.
The method will make sure to switch to the correct page if necessary before applying the zoom.
let annotationPosition = annotation.boundingBoxlet pageIndex = annotation.absolutePageIndex
// Zoom to the annotation.documentViewController.zoom(toPDFRect: annotationPosition, forPageAt: pageIndex, animated: true)
CGRect annotationPosition = annotation.boundingBox;NSUInteger pageIndex = annotation.absolutePageIndex;
// Zoom to the annotation.[documentViewController zoomToPDFRect:annotationPosition forPageAtIndex:pageIndex animated:YES];
zoom(toPDFRect:forPageAt:animated:)
(opens in a new tab) will automatically go to the given page if some other page is currently being viewed. There’s no need to switch the page manually!
Disabling Zooming
Zooming can be disabled by setting the maximumZoomScale
(opens in a new tab) of PDFConfiguration
to 1
. It’s important to set this value before creating the view. Alternatively, you can set zoomEnabled
(opens in a new tab) to NO
on PDFDocumentViewController
(opens in a new tab):
let controller = PDFViewController(document: document) { $0.maximumZoomScale = 1}
PSPDFViewController *controller = [[PSPDFViewController alloc] initWithDocument:document configuration:[PSPDFConfiguration configurationWithBuilder:^(PSPDFConfigurationBuilder *builder) { builder.maximumZoomScale = 1.0f;}]];