PSPDFRenderTask

Objective-C


@interface PSPDFRenderTask : NSObject

Swift

class RenderTask : 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 = MutableRenderRequest(document: document)
request.pageIndex = 0
request.imageSize = CGSize(width: 320.0, height: 480.0)

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

SDK.shared.renderManager.renderQueue.schedule(task)
  • Unavailable

    Not the designated initializer

    Undocumented

    Declaration

    Objective-C

    PSPDF_EMPTY_INIT_UNAVAILABLE
  • Unavailable

    Not the designated initializer

    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 fulfill.

    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 (nonatomic, readonly) PSPDFRenderRequest *_Nonnull request;

    Swift

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

    Declaration

    Objective-C

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

    Swift

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

    Declaration

    Objective-C

    @property (copy, nullable) void (^) (NSImage *_Nullable, NSError *_Nullable) completionHandler;

    Swift

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

    Declaration

    Objective-C

    @property (readonly, nullable) NSImage *image;

    Swift

    var image: NSImage? { get }
  • true if the task has been cancelled, false otherwise.

    Declaration

    Objective-C

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

    Swift

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

    Declaration

    Objective-C

    @property (readonly, getter=isCompleted) 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: [RenderTask], 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

    Deprecated in PSPDFKit 4.1 for macOS. Use initWithRequest:error: instead.

    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");