PSPDFDataProviding
Objective-C
@protocol PSPDFDataProviding <NSObject, NSSecureCoding>
Swift
protocol DataProviding : NSSecureCoding, NSObjectProtocol
This protocol is to be used by all possible data providers for PDF access.
E.g. a FileDataProvider
or AESCryptoDataProvider
.
Note
Ensure that your implementation is thread safe. Data might be fetched from multiple threads, in random chunks.-
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 (nonatomic, readonly, nullable) NSData *data;
Swift
var data: Data? { get }
-
Returns the size of the data.
Declaration
Objective-C
@property (nonatomic, readonly) uint64_t size;
Swift
var size: UInt64 { get }
-
Returns a UID that enables you to uniquely identify this data provider, even after re-starting the application.
Declaration
Objective-C
@property (nonatomic, readonly) NSString *_Nonnull UID;
Swift
var uid: String { get }
-
Specifies which additional operations are supported, if any.
Declaration
Objective-C
@property (nonatomic, readonly) PSPDFDataProvidingAdditionalOperations additionalOperationsSupported;
Swift
var additionalOperationsSupported: DataProvidingAdditionalOperations { 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?
-
The public key to identify the data source. This should be set before the data provider is used in a
Document
. Used for special types of licenses only.Declaration
Objective-C
@property (nonatomic, nullable) NSData *signature;
Swift
var signature: Data? { get set }
-
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 (nonatomic, readonly, nullable) NSProgress *progress;
Swift
optional var progress: Progress? { 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
replaceContents(with:)
when appropriate.Declaration
Objective-C
- (nullable id<PSPDFDataSink>) createDataSinkWithOptions:(PSPDFDataSinkOptions)options error:(NSError *_Nullable *_Nullable)error;
Swift
optional func createDataSink(options: DataSinkOptions = []) throws -> DataSink
-
This method should replace your current data with the one written into
replacementDataSink
.When called by PSPDFKit,
replacementDataSink
is the object instantiated increateDataSinkWithOptions:
. Depending onreplacementDataSink.options
, you either have to append or replace the data.Declaration
Objective-C
- (BOOL)replaceContentsWithDataSink: (nonnull id<PSPDFDataSink>)replacementDataSink error:(NSError *_Nullable *_Nullable)error;
Swift
optional func replaceContents(with replacementDataSink: DataSink) throws
-
Whether it is acceptable to call
replaceContents(with:)
whenadditionalOperationsSupported
contains.write
.If this method is not implemented the behavior defaults to
true
.Declaration
Objective-C
@optional @property (nonatomic, readonly) BOOL canWrite;
Swift
optional var canWrite: Bool { get }
-
This method should delete any data that is referenced by this data provider. 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 underlying file was replaced.
-
Toggle if a document using this data provider should use the disk cache. If not implemented, enabled is assumed.
Declaration
Objective-C
@optional @property (nonatomic, readonly) BOOL useDiskCache;
Swift
optional var useDiskCache: Bool { get }
-
Deprecated
Deprecated in PSPDFKit 4.3 for macOS. Please rename your implementation to
replaceContents(with:)
/-replaceContentsWithDataSink:error:
This method should replace your current data with the one written into
replacementDataSink
.When called by PSPDFKit,
replacementDataSink
is the object instantiated increateDataSink(options:)
. Depending onreplacementDataSink.options
, you either have to append or replace the data.Declaration
Objective-C
- (BOOL)replaceWithDataSink:(nonnull id<PSPDFDataSink>)replacementDataSink error:(NSError *_Nullable *_Nullable)error;
Swift
optional func replace(with replacementDataSink: DataSink) throws