PSPDFProcessor


@interface PSPDFProcessor : NSObject

Create, merge or modify PDF documents. Also allows to flatten annotation data.

  • Generates a new document based on PSPDFProcessorConfiguration and stores it to fileURL.

    Declaration

    Objective-C

    + (BOOL)generatePDFFromConfiguration:
                (nonnull PSPDFProcessorConfiguration *)configuration
                             saveOptions:
                                 (nullable PSPDFProcessorSaveOptions *)saveOptions
                           outputFileURL:(nonnull NSURL *)fileURL
                           progressBlock:(nullable PSPDFProgressBlock)progressBlock
                                   error:(NSError *_Nullable *_Nullable)error;

    Swift

    class func generatePDF(from configuration: PSPDFProcessorConfiguration, saveOptions: PSPDFProcessorSaveOptions?, outputFileURL fileURL: URL, progressBlock: PSPDFProgressBlock? = nil) throws

    Parameters

    configuration

    The configuration you want to use for the processing.

    saveOptions

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

    fileURL

    The URL to save the generated document to. Needs to be a fileURL.

    progressBlock

    The progress block to monitor progress on the generation process. Can be NULL. The progress block is called on an arbitrary queue.

    error

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

    Return Value

    YES if generation was successful, NO otherwise.

  • Generates a new document based on PSPDFProcessorConfiguration and returns it.

    Note

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

    See

    +generatePDFFromConfiguration:saveOptions:outputFileURL:progressBlock:error:

    Declaration

    Objective-C

    + (nullable NSData *)
    generatePDFFromConfiguration:
        (nonnull PSPDFProcessorConfiguration *)configuration
                     saveOptions:(nullable PSPDFProcessorSaveOptions *)saveOptions
                   progressBlock:(nullable PSPDFProgressBlock)progressBlock
                           error:(NSError *_Nullable *_Nullable)error;

    Swift

    class func generatePDF(from configuration: PSPDFProcessorConfiguration, saveOptions: PSPDFProcessorSaveOptions?, progressBlock: PSPDFProgressBlock? = nil) throws -> Data

    Parameters

    configuration

    The configuration you want to use for the processing.

    saveOptions

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

    progressBlock

    The progress block to monitor progress on the generation process. Can be NULL. The progress block is called on an arbitrary queue.

    error

    On return, contains an error if one occured 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 PSPDFProcessorConfiguration and returns it.

    Declaration

    Objective-C

    + (BOOL)generatePDFFromConfiguration:
                (nonnull PSPDFProcessorConfiguration *)configuration
                             saveOptions:
                                 (nullable PSPDFProcessorSaveOptions *)saveOptions
                          outputDataSink:(nonnull id<PSPDFDataSink>)outputDataSink
                           progressBlock:(nullable PSPDFProgressBlock)progressBlock
                                   error:(NSError *_Nullable *_Nullable)error;

    Swift

    class func generatePDF(from configuration: PSPDFProcessorConfiguration, saveOptions: PSPDFProcessorSaveOptions?, outputDataSink: PSPDFDataSink, progressBlock: PSPDFProgressBlock? = nil) throws

    Parameters

    configuration

    The configuration you want to use for the processing.

    saveOptions

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

    outputDataSink

    The generated document will be written into outputDataSink.

    progressBlock

    The progress block to monitor progress on the generation process. Can be NULL. The progress block is called on an arbitrary queue.

    error

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

    Return Value

    YES if generation was successful, NO otherwise.

  • Generates a PDF from a string. Does allow simple html tags. - note: Will not work with complex HTML pages. e.g. @"This is a <b>test</b> in <span style='color:red'>color.</span>

    Declaration

    Objective-C

    + (void)generatePDFFromHTMLString:(nonnull NSString *)HTML
                        outputFileURL:(nonnull NSURL *)fileURL
                              options:
                                  (nullable NSDictionary<NSString *, id> *)options
                      completionBlock:
                          (nullable void (^)(NSError *_Nullable))completionBlock;

    Swift

    class func generatePDF(fromHTMLString HTML: String, outputFileURL fileURL: URL, options: [String : Any]? = nil, completionBlock: ((Error?) -> Void)? = nil)
  • Like the above, but create a temporary PDF in memory.

    Declaration

    Objective-C

    + (void)generatePDFFromHTMLString:(nonnull NSString *)HTML
                              options:
                                  (nullable NSDictionary<NSString *, id> *)options
                      completionBlock:
                          (nullable void (^)(NSData *_Nonnull,
                                             NSError *_Nullable))completionBlock;

    Swift

    class func generatePDF(fromHTMLString HTML: String, options: [String : Any]? = nil, completionBlock: ((Data, Error?) -> Void)? = nil)
  • Renders a PDF from an URL (web or fileURL). Upon completion, the completionBlock will be called.

    Loading the URL is non-blocking, however the conversion uses the iOS printing infrastructure and only works on the main thread. Larger documents might stall your application for a while. Download the document to a temporary folder and show a blocking progress HUD while the conversion is running to mitigate the blocking.

    Supported are web pages and certain file types like pages, keynote, word, powerpoint, excel, rtf, jpg, png, … See https://developer.apple.com/library/ios/#qa/qa2008/qa1630.html for the full list.

    Note

    FILE/OFFICE CONVERSION IS AN EXPERIMENTAL FEATURE AND WE CAN’T OFFER SUPPORT FOR CONVERSION ISSUES. If you require a 1:1 conversion, you need to convert those files on a server with a product that is specialized for this task.

    Certain documents might not have the correct pagination. (Try to manually define PSPDFProcessorPageRectKey to fine-tune this.)

    options can contain both the PSPDF constants listed above and any kCGPDFContext constants. For example, to password protect the PDF, you can use: @{(id)kCGPDFContextUserPassword: password, (id)kCGPDFContextOwnerPassword: password, (id)kCGPDFContextEncryptionKeyLength: @128}

    Other useful properties are: - kCGPDFContextAllowsCopying - kCGPDFContextAllowsPrinting - kCGPDFContextKeywords - kCGPDFContextAuthor

    Note

    Requires the PSPDFFeatureMaskPDFCreation feature flag.

    @warning Don’t manually override NSOperation’s completionBlock. If this helper is used, operation will be automatically queued in conversionOperationQueue. When a password is set, only link annotations can be added as dictionary (this does not affect flattening)

    Don’t use this for PDF files!

    Declaration

    Objective-C

    + (nullable PSPDFConversionOperation *)
    generatePDFFromURL:(nonnull NSURL *)inputURL
         outputFileURL:(nonnull NSURL *)outputURL
               options:(nullable NSDictionary<NSString *, id> *)options
       completionBlock:
           (nullable void (^)(NSURL *_Nonnull, NSError *_Nullable))completionBlock;

    Swift

    class func generatePDF(from inputURL: URL, outputFileURL outputURL: URL, options: [String : Any]? = nil, completionBlock: ((URL, Error?) -> Void)? = nil) -> PSPDFConversionOperation?
  • Will create a PDF in-memory.

    Declaration

    Objective-C

    + (nonnull PSPDFConversionOperation *)
    generatePDFFromURL:(nonnull NSURL *)inputURL
               options:(nullable NSDictionary<NSString *, id> *)options
       completionBlock:
           (nullable void (^)(NSData *_Nonnull, NSError *_Nullable))completionBlock;

    Swift

    class func generatePDF(from inputURL: URL, options: [String : Any]? = nil, completionBlock: ((Data, Error?) -> Void)? = nil) -> PSPDFConversionOperation