PSPDFProcessor

Objective-C


@interface PSPDFProcessor : NSObject

Swift

class Processor : NSObject

Create, merge or modify PDF documents. Can also flatten annotation data.

  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic, weak) id<PSPDFProcessorDelegate> delegate

    Swift

    weak var delegate: ProcessorDelegate? { get set }
  • Instantiates a PSPDFProcessor with the given configuration and security options.

    See

    -initWithOptions: if you want to generate a PDF from an HTML string or URL.

    Declaration

    Objective-C

    - (nonnull instancetype)
        initWithConfiguration:(nonnull PSPDFProcessorConfiguration *)configuration
              securityOptions:
                  (nullable PSPDFDocumentSecurityOptions *)securityOptions;

    Parameters

    configuration

    The configuration you want to use for the processing.

    securityOptions

    The save options to use or nil if you want to keep the ones from the original document.

    Return Value

    PSPDFProcessor instance.

  • Generates a new document based on the configuration and security options set on the receiver, and stores it to fileURL.

    Declaration

    Objective-C

    - (BOOL)writeToFileURL:(nonnull NSURL *)fileURL
                     error:(NSError *_Nullable *_Nullable)error;

    Swift

    func write(toFileURL fileURL: URL) throws

    Parameters

    fileURL

    The URL to save the generated document to. Needs to be a file URL. There should be no file at this URL prior to calling this method. This method will throw an error in the case a file already exists.

    error

    On return, contains an error if one occurred while generating the document.

    Return Value

    true if generation was successful, false otherwise.

  • Generates a new document based on the configuration and security options set on the receiver.

    Note

    The data object will be memory-mapped if possible, however we encourage you to use the file url based variant instead.

    Declaration

    Objective-C

    - (nullable NSData *)dataWithError:(NSError *_Nullable *_Nullable)error;

    Swift

    func data() throws -> Data

    Parameters

    error

    On return, contains an error if one occurred while generating the document.

    Return Value

    An NSData object containing the generated document. If possible, this object is memory-mapped.

  • Generates a new document based on the configuration and security options set on the receiver, and writes it to the PSPDFDataSink provided.

    Declaration

    Objective-C

    - (BOOL)outputToDataSink:(nonnull id<PSPDFDataSink>)outputDataSink
                       error:(NSError *_Nullable *_Nullable)error;

    Swift

    func output(to outputDataSink: DataSink) throws

    Parameters

    outputDataSink

    The generated document will be written into outputDataSink.

    error

    On return, contains an error if one occurred while generating the document.

    Return Value

    true if generation was successful, false otherwise.

  • Cancels the current PDF generation process associated with the receiver.

    The cancellation is asynchronous, and only happens until the current page that’s being processes is completed.

    Declaration

    Objective-C

    - (void)cancel;

    Swift

    func cancel()
  • Converts an Office file to a PDF by uploading it to a server that performs the actual conversion. Once the server completes the conversion, the resulting PDF file is downloaded and kept in memory.

    Supported document types: Word, Excel and Powerpoint.

    Note

    WARNING: This API downloads and loads the entire converted PDF file into memory.

    Declaration

    Objective-C

    + (nullable PSPDFOfficeConversionOperation *)
        generatePDFFromURL:(nonnull NSURL *)inputURL
                 serverURL:(nonnull NSURL *)serverURL
                       JWT:(nonnull NSString *)JWT
           completionBlock:(nullable void (^)(NSData *_Nullable,
                                              NSError *_Nullable))completionBlock;

    Swift

    class func generatePDF(from inputURL: URL, serverURL: URL, jwt JWT: String, completionBlock: ((Data?, Error?) -> Void)? = nil) -> PSPDFOfficeConversionOperation?

    Parameters

    inputURL

    The URL of the file to generate the PDF from.

    serverURL

    The URL of the server that will perform the document conversion.

    JWT

    The JSON Web token used to authenticate access to the server.

    completionBlock

    Called when the converted PDF has finished downloading. First parameter is the data of the rendered PDF, second parameter is the resulting error, if any.

    Return Value

    Operation of converting the Office file to PDF that will be automatically enqueued.

  • This method performs the same task as +generatePDFFromURL:serverURL:jwt:completionBlock, but the generated PDF is saved to disk.

    Supported document types: Word, Excel and Powerpoint.

    Note

    This API streams the converted PDF file and writes it to disk without loading it entirely into memory.

    Declaration

    Objective-C

    + (nullable PSPDFOfficeConversionOperation *)
        generatePDFFromURL:(nonnull NSURL *)inputURL
                 serverURL:(nonnull NSURL *)serverURL
                       JWT:(nonnull NSString *)JWT
             outputFileURL:(nonnull NSURL *)outputFileURL
           completionBlock:(nullable void (^)(NSURL *_Nullable,
                                              NSError *_Nullable))completionBlock;

    Swift

    class func generatePDF(from inputURL: URL, serverURL: URL, jwt JWT: String, outputFileURL: URL, completionBlock: ((URL?, Error?) -> Void)? = nil) -> PSPDFOfficeConversionOperation?

    Parameters

    inputURL

    The URL of the file to generate the PDF from.

    serverURL

    The URL of the server that will perform the document conversion.

    JWT

    The JSON Web token used to authenticate access to the server.

    outputFileURL

    The URL the generated PDF is going to be saved to. Needs to be a file URL. Note that the actual output file URL might be different at the end.

    completionBlock

    Called when the converted PDF has finished downloading and has been saved to disk. First parameter is the actual output file URL of the converted PDF, second parameter is the resulting error, if any.

    Return Value

    Operation of converting the Office file to PDF that will be automatically enqueued.

  • Cancel all ongoing conversion operations.

    Declaration

    Objective-C

    + (void)cancelAllConversionOperations;

    Swift

    class func cancelAllConversionOperations()
  • Deprecated

    Deprecated in PSPDFKit 4.5 for macOS. Renamed to cancelAllConversionOperations.

    Deprecated. Renamed to cancelAllConversionOperations.

    Declaration

    Objective-C

    + (void)cancellAllConversionOperations;

    Swift

    class func cancellAllConversionOperations()