RenderPagesToFilesParallel
Rendering and printing
Description
Renders every page from StartPage to EndPage of the source PDF to one image file per page, using a pool of parallel TTask workers. Each worker creates its own TPDFlib instance on the same file (TPDFlib is not thread-safe), CoInitializes its thread for GDI+ apartment safety, and renders pages claimed from a shared atomic counter until the range is exhausted.
This scales near-linearly with CPU cores for CPU-bound raster output (BMP/PNG/TIFF). MaxWorkers controls the pool width; pass 0 or negative for auto (min of page count and CPU count). Windows-only: CoInitialize and GDI+ are Windows primitives.
Syntax
Delphi
Function TPDFlib.RenderPagesToFilesParallel(Const FileName, Password: WideString; DPI: Double; StartPage, EndPage, Options: Integer; Const OutputPattern: WideString; MaxWorkers: Integer): Integer;
Parameters
| FileName, Password | Source PDF path and its password (empty if unencrypted) |
|---|---|
| DPI | Render resolution |
| StartPage, EndPage | 1-based inclusive page range |
| Options | Format (same as RenderPageToFile: 0=BMP 1=JPEG 5=PNG ...) |
| OutputPattern | Output path; '%p' is replaced by the page number, else the number is appended |
| MaxWorkers | Pool width (0 = auto, capped at page count and CPU count) |
Return values
| >= 0 | Number of pages successfully rendered (single-page failures are isolated, not fatal) |
|---|