PSPDFFileAnnotationProvider


@interface PSPDFFileAnnotationProvider : PSPDFContainerAnnotationProvider

Default implementation of the PSPDFAnnotationProvider protocol that uses the PDF document as source/target to load/save annotations. You almost always want to use the PSPDFFileAnnotationProvider in your PSPDFAnnotationManager. You can also use the PSPDFFileAnnotationProvider inside a custom annotation provider, to parse PDF annotations once and then manage them in your custom database. - note: Subclassing PSPDFFileAnnotationProvider will lead to slower PSPDFProcessor performance and is not recommended. This will be blocked in future versions.

  • Undocumented

    Declaration

    Objective-C

    
    @interface PSPDFFileAnnotationProvider : PSPDFContainerAnnotationProvider
  • Undocumented

    Declaration

    Objective-C

    
    @interface PSPDFFileAnnotationProvider : PSPDFContainerAnnotationProvider
  • Initializes the file annotation provider with the document provider.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithDocumentProvider:
        (nonnull PSPDFDocumentProvider *)documentProvider;

    Swift

    init(documentProvider: PSPDFDocumentProvider)
  • Set to enable auto-detection of various link types. Defaults to PSPDFTextCheckingTypeNone. - warning: Detecting links might be an expensive operation.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic)
        PSPDFTextCheckingType autodetectTextLinkTypes;

    Swift

    var autodetectTextLinkTypes: PSPDFTextCheckingType { get set }
  • Performance optimized access.

    The default implementation is lazy loaded (and of course thread safe); hitting a dictionary cache first and blocks if no cache is found. After the first expensive call, this method is basically free. Ensure that you’re using a similar cache if you replace this method with your own.

    Declaration

    Objective-C

    - (nullable NSArray<__kindof PSPDFAnnotation *> *)annotationsForPageAtIndex:
        (NSUInteger)pageIndex;

    Swift

    func annotationsForPage(at pageIndex: UInt) -> [PSPDFAnnotation]?
  • Will add the annotation to the current annotation array. Will accept any annotations. - parameter: annotations An array of PSPDFAnnotation objects to be added. - parameter: options Insertion options (see the PSPDFAnnotationOption... constants in PSPDFAnnotationManager.h).

    Declaration

    Objective-C

    - (nullable NSArray<__kindof PSPDFAnnotation *> *)
    addAnnotations:(nonnull NSArray<__kindof PSPDFAnnotation *> *)annotations
           options:(nullable NSDictionary<NSString *, id> *)options;

    Swift

    func add(_ annotations: [PSPDFAnnotation], options: [String : Any]? = nil) -> [PSPDFAnnotation]?

    Parameters

    annotations

    An array of PSPDFAnnotation objects to be added.

    options

    Insertion options (see the PSPDFAnnotationOption... constants in PSPDFAnnotationManager.h).

  • Annotations are either removed (PSPDFAnnotationsRemovedNotification) or soft-deleted if they are already saved in the PDF. In case they are soft-deleted, a PSPDFAnnotationChangedNotification with isDeleted as keyPath is sent instead. - parameter: annotations An array of PSPDFAnnotation objects to be removed. - parameter: options Deletion options (see the PSPDFAnnotationOption... constants in PSPDFAnnotationManager.h).

    Declaration

    Objective-C

    - (nullable NSArray<__kindof PSPDFAnnotation *> *)
    removeAnnotations:(nonnull NSArray<__kindof PSPDFAnnotation *> *)annotations
              options:(nullable NSDictionary<NSString *, id> *)options;

    Swift

    func remove(_ annotations: [PSPDFAnnotation], options: [String : Any]? = nil) -> [PSPDFAnnotation]?

    Parameters

    annotations

    An array of PSPDFAnnotation objects to be removed.

    options

    Deletion options (see the PSPDFAnnotationOption... constants in PSPDFAnnotationManager.h).

  • Removes all annotation and re-evaluates the document on next access.

    Declaration

    Objective-C

    - (void)clearCache;

    Swift

    func clearCache()
  • Try to load annotations from file and set them if successful.

    Declaration

    Objective-C

    - (BOOL)tryLoadAnnotationsFromFileWithError:
        (NSError *_Nullable *_Nullable)error;

    Swift

    func tryLoadAnnotationsFromFile() throws
  • This defaults to PSPDFAnnotationTypeAll&~PSPDFAnnotationTypeLink by default. Change this to PSPDFAnnotationTypeAll to also allow link annotation saving. Links are not saved by default since some documents have a crazy high amount of link annotations which would make saving slow. - warning: Never exclude PSPDFAnnotationTypeWidget - Forms are specially handled.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) PSPDFAnnotationType saveableTypes;

    Swift

    var saveableTypes: PSPDFAnnotationType { get set }
  • What annotation types should be parsed from the PDF. Defaults to PSPDFAnnotationTypeAll.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) PSPDFAnnotationType parsableTypes;

    Swift

    var parsableTypes: PSPDFAnnotationType { get set }
  • Path where annotations are being saved if saving to external file is enabled. Default’s to self.documentProvider.document.cacheDirectory + annotations_%d.pspdfkit. The number is omitted in the usual case with only one documentProvider. If a file has multiple document providers, we’ll write annotations.pspdfkit,annotations_2.pspdfkit and so on.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, null_resettable)
        NSString *annotationsPath;

    Swift

    var annotationsPath: String! { get set }
  • Parses the page annotation dictionary and returns the newly created annotations. Want to customize annotations right after parsing? This is the perfect place. Will be called from annotationsForPageAtIndex: in a thread safe manner and later cached.

    Declaration

    Objective-C

    - (nullable NSArray<PSPDFAnnotation *> *)parseAnnotationsForPageAtIndex:
        (NSUInteger)pageIndex;

    Swift

    func parseAnnotationsForPage(at pageIndex: UInt) -> [PSPDFAnnotation]?
  • Saving code.

    Declaration

    Objective-C

    - (BOOL)saveAnnotationsWithOptions:
                (nullable NSDictionary<NSString *, id> *)options
                                 error:(NSError *_Nullable *_Nullable)error;

    Swift

    func saveAnnotations(options: [String : Any]? = nil) throws
  • Load annotations (returning NO + eventually an error if it fails)

    Declaration

    Objective-C

    - (nullable NSDictionary<NSNumber *, NSArray<PSPDFAnnotation *> *> *)
    loadAnnotationsWithError:(NSError *_Nullable *_Nullable)error;

    Swift

    func loadAnnotations() throws -> [NSNumber : [PSPDFAnnotation]]