PSPDFDocumentDelegate

@protocol PSPDFDocumentDelegate <NSObject>

Delegate to receive events regarding PSPDFDocument.

  • Callback for a render operation. Will be called on a thread (since rendering is async) You can use the context to add custom drawing.

    Note

    Rendered pages are cached. If you draw dynamic content, you need to disable caching or invalidate the pages on PSPDFCache before a new render request is scheduled.

    See

    - [PSPDFCache invalidateImageFromDocument:invalidateImageFromDocument:pageIndex:]

    Declaration

    Objective-C

    - (void)pdfDocument:(nonnull PSPDFDocument *)document
        didRenderPageAtIndex:(NSUInteger)pageIndex
                   inContext:(nonnull CGContextRef)context
                    withSize:(CGSize)fullSize
               clippedToRect:(CGRect)clipRect
                 annotations:
                     (nullable NSArray<__kindof PSPDFAnnotation *> *)annotations
                     options:(nullable NSDictionary<NSString *, id> *)options;

    Swift

    optional func pdfDocument(_ document: PSPDFDocument, didRenderPageAt pageIndex: UInt, in context: CGContext, with fullSize: CGSize, clippedTo clipRect: CGRect, annotations: [PSPDFAnnotation]?, options: [String : Any]? = nil)
  • Allow resolving custom path tokens (Documents, Bundle are automatically resolved; you can add e.g. Book and resolve this here). Will only get called for unknown tokens.

    Declaration

    Objective-C

    - (nonnull NSString *)pdfDocument:(nonnull PSPDFDocument *)document
        resolveCustomAnnotationPathToken:(nonnull NSString *)pathToken;

    Swift

    optional func pdfDocument(_ document: PSPDFDocument, resolveCustomAnnotationPathToken pathToken: String) -> String
  • Called before the save process is started. Will assume YES if not implemented. Might be called multiple times during a save process if the document contains multiple document providers. - warning: Might be called from a background thread.

    Declaration

    Objective-C

    - (BOOL)pdfDocument:(nonnull PSPDFDocument *)document
                     provider:(nonnull PSPDFDocumentProvider *)documentProvider
        shouldSaveAnnotations:
            (nonnull NSArray<__kindof PSPDFAnnotation *> *)annotations;

    Swift

    optional func pdfDocument(_ document: PSPDFDocument, provider documentProvider: PSPDFDocumentProvider, shouldSave annotations: [PSPDFAnnotation]) -> Bool
  • Called after saving was successful. If there are no dirty annotations, delegates will not be called. - note: annotations might not include all changes, especially if annotations have been deleted or an annotation provider didn’t implement dirtyAnnotations. - warning: This is called after document providers finish saving annotations, but before the document is saved to disk. Use pdfDocumentDidSave: callback if you want to perform any actions after all changes have beed saved to disk. - warning: Might be called from a background thread.

    Declaration

    Objective-C

    - (void)pdfDocument:(nonnull PSPDFDocument *)document
        didSaveAnnotations:
            (nonnull NSArray<__kindof PSPDFAnnotation *> *)annotations;

    Swift

    optional func pdfDocument(_ document: PSPDFDocument, didSave annotations: [PSPDFAnnotation])
  • Called after saving failed. When an error occurs, annotations will not be the complete set in multi-file documents. - note: annotations might not include all changes, especially if annotations have been deleted or an annotation provider didn’t implement dirtyAnnotations. - warning: Might be called from a background thread.

    Declaration

    Objective-C

    - (void)pdfDocument:(nonnull PSPDFDocument *)document
        failedToSaveAnnotations:
            (nonnull NSArray<__kindof PSPDFAnnotation *> *)annotations
                          error:(nonnull NSError *)error;

    Swift

    optional func pdfDocument(_ document: PSPDFDocument, failedToSave annotations: [PSPDFAnnotation], error: Error)
  • Called after saving was successful. If document wasn’t modified, delegates will not be called. - warning: Might be called from a background thread.

    Declaration

    Objective-C

    - (void)pdfDocumentDidSave:(nonnull PSPDFDocument *)document;

    Swift

    optional func pdfDocumentDidSave(_ document: PSPDFDocument)
  • Called after saving failed. - warning: Might be called from a background thread.

    Declaration

    Objective-C

    - (void)pdfDocument:(nonnull PSPDFDocument *)document
        saveDidFailWithError:(nonnull NSError *)error;

    Swift

    optional func pdfDocument(_ document: PSPDFDocument, saveDidFailWithError error: Error)
  • Called when an underlying resource of the document is either altered or deleted and the change did not originate from the document itself.

    You can check the fileURL‘s -[NSURL checkResourceIsReachableAndReturnError:] if you want to determine if the file was deleted or updated.

    Note

    A PSPDFViewController does handle this internally already, however if you are creating and modifying PSPDFDocuments outside of PSPDFViewController, this message is important. If you do not react to this problem correctly, this may result in data loss.

    Declaration

    Objective-C

    - (void)pdfDocument:(nonnull PSPDFDocument *)document
        underlyingFileDidChange:(nonnull NSURL *)fileURL;

    Swift

    optional func pdfDocument(_ document: PSPDFDocument, underlyingFileDidChange fileURL: URL)

    Parameters

    document

    the document that noticed the change.

    fileURL

    the file url pointing to the resource that was changed or deleted.