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.0f, 480.0f);

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

[PSPDFKit.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

PSPDFKit.sharedInstance.renderManager.renderQueue.schedule(task)
  • Undocumented

    Declaration

    Objective-C

    
    @interface PSPDFRenderTask : NSObject
  • Undocumented

    Declaration

    Objective-C

    
    @interface PSPDFRenderTask : NSObject
  • Initializes a task with a given render request.

    The render request is copyied 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;

    Swift

    init?(request: PSPDFRenderRequest)

    Parameters

    request

    The render request the task should fullfil.

    Return Value

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

  • Undocumented

    Declaration

    Objective-C

    
    @interface PSPDFRenderTask : NSObject
  • 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 *_Nonnull)
        completionHandler;

    Swift

    var completionHandler: ((UIImage) -> 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 }
  • 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.