RenderWorker Class

Definition

Renders the viewer's content tiles in a Web Worker (#357): a second .NET runtime, booted from the app's own framework files, holds its own copy of each document, builds its display lists and rasterizes its tiles, and hands each tile back as a transferable ImageBitmap. The page's thread then only plans frames, presents finished tiles and draws the annotation and form-field overlays (so edits never wait for the worker and never reach its copy). It needs no cross-origin isolation, so it works on any static host; where Web Workers are missing, or the app does not serve the worker, the viewer draws every tile itself.

[SupportedOSPlatform("browser")]
public static class RenderWorker

Remarks

Spec #33 viewer capability 1 (#357). Strictly opt-in: the library never starts the worker by itself. It costs a second .NET runtime (boot time and memory, see docs/benchmarks/viewer-render-worker.md), so an app that wants it does all three of: serve it from Main, start it with StartAsync(Nullable<TimeSpan>), and give each session a renderer with UseRemoteRenderer(IRemoteTileRenderer). Without them every tile renders on the page's thread, as before.

The app's Main runs in the worker too, and must start with:

if (RenderWorker.IsWorker)
{
    RenderWorker.Serve(() => new PdfEngine(options)); // the engine the page opens documents with
    return;
}

Then StartAsync(Nullable<TimeSpan>) starts the worker once, and each document opened from bytes gets a renderer with Open(ReadOnlySpan<Byte>, DisplayIntent) (options.UseRemoteRenderer(RenderWorker.Open(bytes, options.Intent)!)) or, for a document read through range requests, Open(Uri, DisplayIntent). Password-protected documents are drawn on the page's thread.

Tip: use kind:method, kind:property, kind:ctor. Press Esc to clear.

Properties (2)

Methods (4)