PSPDFViewControllerDelegate

@protocol PSPDFViewControllerDelegate <NSObject>

Implement this delegate in your UIViewController to get notified of PSPDFViewController events.

  • Control scrolling to pages. Not implementing this will return YES. - note: Returning NO will not prevent the user from changing pages by scrolling.

    Declaration

    Objective-C

    - (BOOL)pdfViewController:(nonnull PSPDFViewController *)pdfController
        shouldScrollToPageAtIndex:(NSUInteger)pageIndex;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, shouldScrollToPageAt pageIndex: UInt) -> Bool
  • Controller did show/scrolled to a new page. (at least 51% of it is visible)

    Declaration

    Objective-C

    - (void)pdfViewController:(nonnull PSPDFViewController *)pdfController
              didShowPageView:(nonnull PSPDFPageView *)pageView;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, didShow pageView: PSPDFPageView)
  • Called if a page view updated the full size image of the pdf page it is displaying.

    Usually this happens either after a render pass or after retrieving an image from the cache.

    Declaration

    Objective-C

    - (void)pdfViewController:(nonnull PSPDFViewController *)pdfController
            didRenderPageView:(nonnull PSPDFPageView *)pageView;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, didRenderPageView pageView: PSPDFPageView)

    Parameters

    pdfController

    The pdf view controller the page view belongs to.

    pageView

    The page view that updated its image.

  • Called when a page view schedules a render task to update its content view.

    Once the render taks completed, pdfViewController:didFinishRenderTaskForPageView: will be called.

    See

    pdfViewController:didFinishRenderTaskForPageView:

    Declaration

    Objective-C

    - (void)pdfViewController:(nonnull PSPDFViewController *)pdfController
        willScheduleRenderTaskForPageView:(nonnull PSPDFPageView *)pageView;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, willScheduleRenderTaskFor pageView: PSPDFPageView)

    Parameters

    pdfController

    The pdf view controller the page view belongs to.

    pageView

    The page view that scheduled the render task.

  • Called when a render task finishes that was scheduled by a page view to update its content view.

    See

    pdfViewController:didFinishRenderTaskForPageView:

    Declaration

    Objective-C

    - (void)pdfViewController:(nonnull PSPDFViewController *)pdfController
        didFinishRenderTaskForPageView:(nonnull PSPDFPageView *)pageView;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, didFinishRenderTaskFor pageView: PSPDFPageView)

    Parameters

    pdfController

    The pdf view controller the page view belongs to.

    pageView

    The page view that scheduled the render task.

  • Called when a page view sets an image on its content view. This image can either be a full sized image, a smaller image that is used while waiting for a full sized image, or nil. The image might be aquired from the cache or from a render task.

    Declaration

    Objective-C

    - (void)pdfViewController:(nonnull PSPDFViewController *)pdfController
        didUpdateContentImageForPageView:(nonnull PSPDFPageView *)pageView
                           isPlaceholder:(BOOL)placeholder;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, didUpdateContentImageFor pageView: PSPDFPageView, isPlaceholder placeholder: Bool)

    Parameters

    pdfController

    The pdf view controller the page view belongs to.

    pageView

    The page view that updated its content view’s image.

    placeholder

    YES if the image set in the content view is just a placeholder while waiting for a full resolution image from the render engine. The placeholder image might also be nil.

  • Called after pdf page has been loaded and added to the pagingScrollView.

    Declaration

    Objective-C

    - (void)pdfViewController:(nonnull PSPDFViewController *)pdfController
              didLoadPageView:(nonnull PSPDFPageView *)pageView;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, didLoad pageView: PSPDFPageView)
  • Called before a pdf page will be unloaded and removed from the pagingScrollView.

    Declaration

    Objective-C

    - (void)pdfViewController:(nonnull PSPDFViewController *)pdfController
           willUnloadPageView:(nonnull PSPDFPageView *)pageView;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, willUnload pageView: PSPDFPageView)
  • Will be called before the page rect has been dragged.

    Declaration

    Objective-C

    - (void)pdfViewController:(nonnull PSPDFViewController *)pdfController
         didBeginPageDragging:(nonnull UIScrollView *)scrollView;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, didBeginPageDragging scrollView: UIScrollView)
  • Will be called after the page rect has been dragged. If decelerate is YES, this will be called again after deceleration is complete.

    You can also change the target with changing targetContentOffset.

    This delegate combines the following scrollViewDelegates: - scrollViewWillEndDragging: / scrollViewDidEndDragging: - scrollViewDidEndDecelerating:

    Note

    Be careful to not dereference a nil pointer in targetContentOffset. To get more delegate options, you can subclass PSPDFScrollView and use all available delegates of UIScrollViewDelegate. (don’t forget calling super). Depending on the configured pageTransition, this might be called for several distinct scroll views. Ensure that scrollView == self.pagingScrollView if you are only interested in dragging between pages.

    Declaration

    Objective-C

    - (void)pdfViewController:(nonnull PSPDFViewController *)pdfController
           didEndPageDragging:(nonnull UIScrollView *)scrollView
               willDecelerate:(BOOL)decelerate
                 withVelocity:(CGPoint)velocity
          targetContentOffset:(inout nullable CGPoint *)targetContentOffset;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, didEndPageDragging scrollView: UIScrollView, willDecelerate decelerate: Bool, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer
  • Will be called after the paging animation is complete. This method will be called when animated scrolling ends (e.g. a call to -[PSPDFViewController setPageIndex:animated:] with animation enabled or animated content offset changes). Use pdfViewController:didEndPageDragging:willDecelerate:withVelocity:targetContentOffset: to determine when gesture-based page navigation ends.

    Declaration

    Objective-C

    - (void)pdfViewController:(nonnull PSPDFViewController *)pdfController
        didEndPageScrollingAnimation:(nonnull UIScrollView *)scrollView;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, didEndPageScrollingAnimation scrollView: UIScrollView)
  • Will be called before the zoom level starts to change.

    Declaration

    Objective-C

    - (void)pdfViewController:(nonnull PSPDFViewController *)pdfController
          didBeginPageZooming:(nonnull UIScrollView *)scrollView;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, didBeginPageZooming scrollView: UIScrollView)
  • Will be called after the zoom level has been changed, either programmatically or manually.

    Declaration

    Objective-C

    - (void)pdfViewController:(nonnull PSPDFViewController *)pdfController
            didEndPageZooming:(nonnull UIScrollView *)scrollView
                      atScale:(CGFloat)scale;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, didEndPageZooming scrollView: UIScrollView, atScale scale: CGFloat)
  • Return a PSPDFDocument for a relative path. If this returns nil, we try to find the PDF ourselves with using the current document’s basePath.

    Declaration

    Objective-C

    - (nullable PSPDFDocument *)pdfViewController:
                                    (nonnull PSPDFViewController *)pdfController
                          documentForRelativePath:(nonnull NSString *)relativePath;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, documentForRelativePath relativePath: String) -> PSPDFDocument?
  • didTapOnPageView: will be called if a user taps on the page view.

    Taps that can’t be associated to a specific pageView will still call this method, but pageView is nil and the point will be relative to the view of the PSPDFViewController. This doesn’t mean that this method is called when a tap is outside the pageView.

    Return YES if you want to set this touch as processed; this will disable automatic touch processing like showing/hiding the HUDView or scrolling to the next/previous page.

    Note

    This will not send events when the controller is in thumbnail view.

    PSPDFPageCoordinates has been replaced by just CGPoint viewPoint. You can easily calculate other needed coordinates: e.g. to get the pdfPoint: [pageView convertViewPointToPDFPoint:viewPoint] screenPoint: [pageView convertPoint:tapPosition fromView:pageView] zoomScale: pageView.scrollView.zoomScale pageInfo: pageView.pageInfo

    Declaration

    Objective-C

    - (BOOL)pdfViewController:(nonnull PSPDFViewController *)pdfController
             didTapOnPageView:(nonnull PSPDFPageView *)pageView
                      atPoint:(CGPoint)viewPoint;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, didTapOn pageView: PSPDFPageView, at viewPoint: CGPoint) -> Bool
  • Similar to didTapOnPageView: invoked after 0.35 sec of tap-holding. LongPress and tap are mutually exclusive. Return YES if you custom-process that event.

    Default handling is (if available) text selection; showing the magnification-loupe. The gestureRecognizer helps you evaluating the state; as this delegate is called on every touch-move.

    Note that there may be unexpected results if you only capture some events (thus, return YES on some movements during the recognition state) as e.g. you might not give the system a chance to clean up the magnification loupe. Either consume all or no events for a recognition cycle.

    Declaration

    Objective-C

    - (BOOL)pdfViewController:(nonnull PSPDFViewController *)pdfController
        didLongPressOnPageView:(nonnull PSPDFPageView *)pageView
                       atPoint:(CGPoint)viewPoint
             gestureRecognizer:
                 (nonnull UILongPressGestureRecognizer *)gestureRecognizer;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, didLongPressOn pageView: PSPDFPageView, at viewPoint: CGPoint, gestureRecognizer: UILongPressGestureRecognizer) -> Bool
  • Called before we show a internal controller (color picker, note editor, …) modally or in a popover. Allows last minute modifications.

    Return NO to process the displaying manually.

    Declaration

    Objective-C

    - (BOOL)pdfViewController:(nonnull PSPDFViewController *)pdfController
         shouldShowController:(nonnull UIViewController *)controller
                      options:(nullable NSDictionary<NSString *, id> *)options
                     animated:(BOOL)animated;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, shouldShow controller: UIViewController, options: [String : Any]? = nil, animated: Bool) -> Bool
  • Called after the controller has been fully displayed.

    Declaration

    Objective-C

    - (void)pdfViewController:(nonnull PSPDFViewController *)pdfController
            didShowController:(nonnull UIViewController *)controller
                      options:(nullable NSDictionary<NSString *, id> *)options
                     animated:(BOOL)animated;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, didShow controller: UIViewController, options: [String : Any]? = nil, animated: Bool)
  • Will be called when viewMode changes.

    Declaration

    Objective-C

    - (void)pdfViewController:(nonnull PSPDFViewController *)pdfController
            didChangeViewMode:(PSPDFViewMode)viewMode;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, didChange viewMode: PSPDFViewMode)
  • Called before the view controller will be dismissed (either by modal dismissal, or popping from the navigation stack). Called before PSPDFKit tries to save any dirty annotation. - note: If you use child view containment then the dismissal might not be properly detected.

    Declaration

    Objective-C

    - (void)pdfViewControllerWillDismiss:
        (nonnull PSPDFViewController *)pdfController;

    Swift

    optional func pdfViewControllerWillDismiss(_ pdfController: PSPDFViewController)
  • Called after the view controller has been dismissed (either by modal dismissal, or popping from the navigation stack). - note: If you use child view containment then the dismissal might not be properly detected.

    Declaration

    Objective-C

    - (void)pdfViewControllerDidDismiss:
        (nonnull PSPDFViewController *)pdfController;

    Swift

    optional func pdfViewControllerDidDismiss(_ pdfController: PSPDFViewController)
  • Called after the view controller changed its controller state or its controller state error.

    Declaration

    Objective-C

    - (void)pdfViewControllerDidChangeControllerState:
        (nonnull PSPDFViewController *)pdfController;

    Swift

    optional func pdfViewControllerDidChangeControllerState(_ pdfController: PSPDFViewController)

    Parameters

    pdfController

    The controller that changed its state.

  • Called every time before an action will be executed. Actions can come from many sources: Links, Forms, or any other annotation type (via additionalActions) Actions can be invoked on trigger events like PSPDFAnnotationTriggerEventMouseDown. Using the back/forward list will also trigger actions.

    Return NO to prevent the PDF action from being executed.

    Note

    This is also called for every subaction the action has.

    Declaration

    Objective-C

    - (BOOL)pdfViewController:(nonnull PSPDFViewController *)pdfController
          shouldExecuteAction:(nonnull PSPDFAction *)action;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, shouldExecute action: PSPDFAction) -> Bool
  • Called every time after an action has been executed. - note: This is also called for every subaction the action has.

    Declaration

    Objective-C

    - (void)pdfViewController:(nonnull PSPDFViewController *)pdfController
             didExecuteAction:(nonnull PSPDFAction *)action;

    Swift

    optional func pdfViewController(_ pdfController: PSPDFViewController, didExecute action: PSPDFAction)