SBSDKPDFPagesExtractor

@interface SBSDKPDFPagesExtractor : NSObject

Class used to extract pages from a PDF file and returns them in various ways. The synchronous functions of this class are running in the same thread that they are called from, so it is up to you to control the concurrency. The asynchronous functions run in a shared queue to prevent memory pressure when running multiple extractions at the same time. It is recommended to use background queues in most cases. Currently the flattening of the PDF document is user’s responsibility. So if the document will have unflattened annotations (except signs), they will not be exported.

  • Extracts pages from a PDF, converts them to JPEGs and writes them to a specified URL. Runs in the same thread that it is called from. No encryption is used here. The compression is set to 0.9. Media box scale value is 2

    Declaration

    Objective-C

    - (nonnull NSArray<NSURL *> *)imageURLsFromPDF:(nonnull NSURL *)pdfURL
                                   outputDirectory:(nonnull NSURL *)outputURL;

    Swift

    func imageURLs(fromPDF pdfURL: URL, outputDirectory outputURL: URL) -> [URL]

    Parameters

    pdfURL

    The URL of the PDF file.

    outputURL

    The output folder where images will be stored. Must be an existing folder.

    Return Value

    An array of URLs with extracted pages as JPEG files. The array will be empty if something is wrong.

  • Extracts pages from a PDF, converts them to JPEGs and writes them to a specified URL. Runs in the same thread that it is called from. No encryption is used here. Media box scale value is 2

    Declaration

    Objective-C

    - (nonnull NSArray<NSURL *> *)imageURLsFromPDF:(nonnull NSURL *)pdfURL
                                       compression:(float)compression
                                   outputDirectory:(nonnull NSURL *)outputURL;

    Swift

    func imageURLs(fromPDF pdfURL: URL, compression: Float, outputDirectory outputURL: URL) -> [URL]

    Parameters

    pdfURL

    The URL of the PDF file.

    compression

    Compression of the output image file. The range is from 0 to 1, where 1 - lossless conversion, 0 - maximum compression is used.

    outputURL

    The output folder where images will be stored. Must be an existing folder.

    Return Value

    An array of URLs with extracted pages as JPEG files. The array will be empty if something is wrong.

  • Extracts pages from a PDF, converts them to JPEGs and writes them to a specified URL. Runs in the same thread that it is called from.

    Declaration

    Objective-C

    - (nonnull NSArray<NSURL *> *)
        imageURLsFromPDF:(nonnull NSURL *)pdfURL
                 scaling:(CGFloat)scaling
             compression:(float)compression
               encrypter:(nullable id<SBSDKStorageCrypting>)encrypter
         outputDirectory:(nonnull NSURL *)outputURL;

    Swift

    func imageURLs(fromPDF pdfURL: URL, scaling: CGFloat, compression: Float, encrypter: SBSDKStorageCrypting?, outputDirectory outputURL: URL) -> [URL]

    Parameters

    pdfURL

    The URL of the PDF file.

    scaling

    Scaling applied to the PDF media box frame while extracting. Affects the output image quality. In most cases the recommended value is 2 and higher.

    compression

    Compression of the output image file. The range is from 0 to 1, where 1 - lossless conversion, 0 - maximum compression is used.

    encrypter

    The encrypter used to encrypt output image files. If nil, no encryption is used.

    outputURL

    The output folder where images will be stored. Must be an existing folder.

    Return Value

    An array of URLs with extracted pages as JPEG files. The array will be empty if something is wrong.

  • Extracts pages from PDF and converts them to an array of UIImages. Nothing is written to disk during this operation. Runs in the same thread, as it is called from. The scaling of the media box is set to 2.

    Declaration

    Objective-C

    - (nonnull NSArray<UIImage *> *)imagesFromPDF:(nonnull NSURL *)pdfURL;

    Swift

    func images(fromPDF pdfURL: URL) -> [UIImage]

    Parameters

    pdfURL

    The URL of the PDF file.

    Return Value

    An array of UIImages with extracted pages. The array will be empty if something is wrong.

  • Extracts pages from PDF and converts them to an array of UIImages. Nothing is written to disk during this operation. Runs in the same thread, as it is called from.

    Declaration

    Objective-C

    - (nonnull NSArray<UIImage *> *)imagesFromPDF:(nonnull NSURL *)pdfURL
                                          scaling:(CGFloat)scaling;

    Swift

    func images(fromPDF pdfURL: URL, scaling: CGFloat) -> [UIImage]

    Parameters

    pdfURL

    The URL of the PDF file.

    scaling

    Scaling applied to the PDF media box frame while extracting. Affects the output image quality. In most cases the recommended value is 2 and higher.

    Return Value

    An array of UIImages with extracted pages. The array will be empty if something is wrong.

  • Extracts pages from PDF and returns them as SBSDKUIDocument. Each page of the PDF will be a separate SBSDKUIPage. Runs in the same thread, as it is called from.

    Declaration

    Objective-C

    - (nonnull SBSDKUIDocument *)documentFromPDF:(nonnull NSURL *)pdfURL;

    Swift

    func document(fromPDF pdfURL: URL) -> SBSDKUIDocument

    Parameters

    pdfURL

    The URL of the PDF file.

    Return Value

    An array of UIImages with extracted pages. The array will be empty if something is wrong.

  • Asynchronously extracts pages from a PDF, converts them to JPEGs and writes them to a specified URL. The array of URLs is passed within the completion handler.

    Declaration

    Objective-C

    - (nullable SBSDKProgress *)
        imageURLsFromPDF:(nonnull NSURL *)pdfURL
                 scaling:(CGFloat)scaling
             compression:(float)compression
               encrypter:(nullable id<SBSDKStorageCrypting>)encrypter
         outputDirectory:(nonnull NSURL *)outputURL
              completion:(nonnull void (^)(NSArray<NSURL *> *_Nonnull))completion;

    Swift

    func imageURLs(fromPDF pdfURL: URL, scaling: CGFloat, compression: Float, encrypter: SBSDKStorageCrypting?, outputDirectory outputURL: URL, completion: @escaping ([URL]) -> Void) -> SBSDKProgress?

    Parameters

    pdfURL

    The URL of the PDF file.

    scaling

    Scaling applied to the PDF media box frame while extracting. Affects the output image quality. In most cases the recommended value is 2 and higher.

    compression

    Compression of the output image file. The range is from 0 to 1, where 1 - lossless conversion, 0 - maximum compression is used.

    encrypter

    The encrypter used to encrypt output image files. If nil, no encryption is used.

    outputURL

    The output folder where images will be stored. Must be an existing folder.

    completion

    The completion handler that delivers the created array of image file URLs.

    Return Value

    A progress object that can be used for cancellation and progress observing. If nil, an error occured.

  • Asynchronously extracts pages from PDF and returns them as SBSDKUIDocument in the completion handler. Each page of the PDF will be a separate SBSDKUIPage. Runs in the same thread, as it is called from.

    Declaration

    Objective-C

    - (nullable SBSDKProgress *)
        documentFromPDF:(nonnull NSURL *)pdfURL
             completion:(nonnull void (^)(SBSDKUIDocument *_Nonnull))completion;

    Swift

    func document(fromPDF pdfURL: URL, completion: @escaping (SBSDKUIDocument) -> Void) -> SBSDKProgress?

    Parameters

    pdfURL

    The URL of the PDF file.

    completion

    The completion handler that delivers the created SBSDKUIDocument.

    Return Value

    A progress object that can be used for cancellation and progress observing. If nil, an error occured.