{{ title }}

This sample describes how to use Web Workers to export FlexGrid to PDF or generate custom PDF in a background thread.

Concept

The export of FlexGrid containing many cells can take up a long time and slow down or block the main thread. Web Workers allow to run JavaScript in the background thread, thus allowing to perform intensive calculations, such as an export, in a separate thread without blocking the UI thread.

From now on, the code that is executed inside the main thread will be called a client code, and the one in the Web Worker's thread - a server code.

How to use

The library provides two classes to work with Web Workers, PdfWebWorker and PdfWebWorkerClient. The first one contains methods designed to work on the server, the second one - on the client.

This is how the interaction with these classes looks like in general:

In the server code all relative paths (to fonts, images, and so on) must be specified relatively to the place where the Web Worker script itself is located.

There are three possible scenarios of using these classes:

Limitations

Because of data being passed between the threads in a serialized form, and server code having no access to DOM, the usage of Web Workers has certain limitations: