PSPDFDataProvider

@protocol PSPDFDataProvider <NSObject, NSSecureCoding>

This protocol is to be used by all possible data providers for PDF access. E.g. a PSPDFDataProvider or PSPDFAESCryptoDataProvider.

Note

This replaces the CGDataProvider support in earlier versions of the SDK.
  • Creates a NSData object with all the data of the provider. Use with caution - this can take a while if the data provider is a remote source and it can quickly exhaust all your memory if it is a big data provider.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) NSData *data;

    Swift

    var data: Data? { get }
  • Returns the size of the data.

    Declaration

    Objective-C

    @property (readonly, nonatomic) uint64_t size;

    Swift

    var size: UInt64 { get }
  • UID

    Returns a UID that enables you to uniquely identify this data provider, even after re-starting the application.

    Declaration

    Objective-C

    @property (readonly, nonatomic) NSString *_Nonnull UID;

    Swift

    var uid: String { get }
  • Specifies which additional operations are supported, if any.

    Declaration

    Objective-C

    @property (readonly, nonatomic)
        PSPDFDataProviderAdditionalOperations additionalOperationsSupported;

    Swift

    var additionalOperationsSupported: PSPDFDataProviderAdditionalOperations { get }
  • Reads and returns data read from offset with size. You have to make sure not to read past the end of your data.

    Declaration

    Objective-C

    - (nullable NSData *)readDataWithSize:(uint64_t)size atOffset:(uint64_t)offset;

    Swift

    func readData(withSize size: UInt64, atOffset offset: UInt64) -> Data?
  • An optional progress object that indicates that the data backing the data provider is still being generated. Be sure to transition into the fully completed progress state only after the data is completely ready for reading.

    Declaration

    Objective-C

    @optional
    @property (readonly, nonatomic, nullable) NSProgress *progress;

    Swift

    optional var progress: Progress? { get }
  • The fileURL if the data provider is backed by a file.

    Declaration

    Objective-C

    @optional
    @property (readonly, nonatomic) NSURL *_Nonnull fileURL;

    Swift

    optional var fileURL: URL { get }
  • This method should create a data sink for your data provider with the given options. PSPDFKit will write all the appropriate data into it and pass it to replaceWithDataSink: when appropriate.

    Declaration

    Objective-C

    - (nullable id<PSPDFDataSink>)
    createDataSinkWithOptions:(PSPDFDataSinkOptions)options
                        error:(NSError *_Nullable *_Nullable)error;

    Swift

    optional func createDataSink(options: PSPDFDataSinkOptions = []) throws -> PSPDFDataSink
  • This method should replace your current data with the one written into replacementDataSink. replacementDataSink is the object instantiated in createDataSinkWithOptions:. Depending on the PSPDFDataSinkOptions used above, you either have to append or replace the data.

    Declaration

    Objective-C

    - (BOOL)replaceWithDataSink:(nonnull id<PSPDFDataSink>)replacementDataSink;

    Swift

    optional func replace(with replacementDataSink: PSPDFDataSink) -> Bool
  • If implemented and additionalOperationsSupported contains PSPDFDataProviderAdditionalOperationWrite, this specifies whether a write can be attempted using replaceWithDataSink:.

    Declaration

    Objective-C

    @optional
    @property (readonly, nonatomic) BOOL canWrite;

    Swift

    optional var canWrite: Bool { get }
  • This method should delete any data that is referenced by this PSPDFDataProvider. PSPDFKit uses this method to delete temporary data, if necessary. Returns YES on successful deletion, NO otherwise.

    Declaration

    Objective-C

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

    Swift

    optional func deleteData() throws
  • Should reset any cached data and restore the data provider to its original state. For file based data providers, this should recreate the file handle in case the underlaying file was replaced.

    Declaration

    Objective-C

    - (void)clearCache;

    Swift

    optional func clearCache()