Web Workers
PDFs supports Worker1 rendering of page thumbnails. Pass thumbnailWorkerURL to UniverPdfsUIPlugin; the Worker uses OffscreenCanvas. This setting does not move the whole PDF editor into a Worker.
Start with installation and basic usage. The following snippets extend that setup. Register the plugins before creating or loading content; replace existing registrations rather than registering a plugin twice.
Main thread
import { UniverPdfsUIPlugin } from '@univerjs-pro/pdfs-ui'univer.registerPlugin(UniverPdfsUIPlugin, { thumbnailWorkerURL: new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' }),})Worker entry
import { startPdfPageThumbnailWorker } from '@univerjs-pro/pdfs-ui'startPdfPageThumbnailWorker()Use a module Worker and a separate entry file. Keep the Worker and main-thread package versions aligned. Rendering and user interaction stay on the main thread.
Footnotes
-
A Web Worker runs JavaScript outside the browser’s main thread and exchanges messages with it. It cannot access the page DOM directly; moving calculations into a Worker does not move the editor UI there. ↩
How is this guide?