PSPDFRenderTask


@interface PSPDFRenderTask : NSObject

A render task is used to create an image from the page (or part of it) of a document.

Depending on the PSPDFRenderRequest cache policy, a render task checks the cache before actually triggering a new rendering.

You create a render task by passing it an instance of PSPDFRenderRequest. Once you have created a render request make sure to fully set it up before scheduling it in a render queue.

A simple example of requesting an image from a page:

PSPDFMutableRenderRequest *request = [[PSPDFMutableRenderRequest alloc] initWithDocument:document];
request.pageIndex = pageIndex;
request.imageSize = CGSizeMake(320.0, 480.0);

PSPDFRenderTask *task = [[PSPDFRenderTask alloc] initWithRequest:request];
task.priority = PSPDFRenderQueuePriorityUtility;
task.delegate = self;

[PSPDFKitGlobal.sharedInstance.renderManager.renderQueue scheduleTask:task];
let request = PSPDFMutableRenderRequest(document: document)
request.pageIndex = 0
request.imageSize = CGSize(width: 320.0, height: 480.0)

let task = PSPDFRenderTask(request: request)!
task.priority = .utility
task.delegate = self

PSPDFKitGlobal.sharedInstance.renderManager.renderQueue.schedule(task)
  • Unavailable

    Undocumented

    Declaration

    Objective-C

    PSPDF_EMPTY_INIT_UNAVAILABLE
  • Unavailable

    Undocumented

    Declaration

    Objective-C

    PSPDF_EMPTY_INIT_UNAVAILABLE
  • Initializes a task with a given render request.

    The render request is copied so you can no longer make changes to it after creating a render task out of it.

    Note

    The initializer verifies the request and returns nil if the request is not valid.

    Declaration

    Objective-C

    - (nullable instancetype)initWithRequest:(nonnull PSPDFRenderRequest *)request
                                       error:(NSError *_Nullable *_Nullable)error;

    Swift

    init(request: PSPDFRenderRequest) throws

    Parameters

    request

    The render request the task should fulfil.

    error

    Error that is set if creating the render task failed, because the render request is invalid.

    Return Value

    An initialized instance that is ready to be scheduled in a render queue.

  • The render request this task is initialized with.

    Declaration

    Objective-C

    @property (readonly, nonatomic) PSPDFRenderRequest *_Nonnull request;

    Swift

    var request: PSPDFRenderRequest { get }
  • The delegate that is used for reporting progress on this render task.

    Declaration

    Objective-C

    @property (readwrite, nonatomic) id<PSPDFRenderTaskDelegate> _Nullable delegate;

    Swift

    weak var delegate: PSPDFRenderTaskDelegate? { get set }
  • The completion handler to be called after the rendering has completed.

    Declaration

    Objective-C

    @property (readwrite, copy, atomic, nullable) void (^)
        (UIImage *_Nullable, NSError *_Nullable) completionHandler;

    Swift

    var completionHandler: ((UIImage?, Error?) -> Void)? { get set }
  • The rendered image after the task has completed.

    Declaration

    Objective-C

    @property (readonly, atomic, nullable) UIImage *image;

    Swift

    var image: UIImage? { get }
  • YES if the task has been cancelled, NO otherwise.

    Declaration

    Objective-C

    @property (readonly, getter=isCancelled, atomic) BOOL cancelled;

    Swift

    var isCancelled: Bool { get }
  • YES if the task has been completed, NO otherwise.

    Declaration

    Objective-C

    @property (readonly, getter=isCompleted, atomic) BOOL completed;

    Swift

    var isCompleted: Bool { get }
  • Cancels a task.

    You will no longer receive any callbacks from this task after cancelling it.

    Declaration

    Objective-C

    - (void)cancel;

    Swift

    func cancel()
  • Groups a number of tasks together and executes a completion handler once all grouped tasks complete.

    Declaration

    Objective-C

    + (void)groupTasks:(nonnull NSArray<PSPDFRenderTask *> *)tasks
        completionHandler:(nonnull void (^)(void))completionHandler;

    Swift

    class func groupTasks(_ tasks: [PSPDFRenderTask], completionHandler: @escaping () -> Void)

    Parameters

    tasks

    The tasks you want to group.

    completionHandler

    The completion handler that is executed once all render tasks in the tasks array completed.

  • Deprecated

    Undocumented

    Declaration

    Objective-C

    - (nullable instancetype)initWithRequest:(PSPDFRenderRequest *)request PSPDF_DEPRECATED(9.1, 4.1, "Use `initWithRequest:error:` instead.") NS_SWIFT_UNAVAILABLE("Use version with error handling");