PDFium Delphi Component Docs

RenderPagesParallel method

Component: TPdf  ·  Unit: PDFium
Renders several page requests concurrently while every worker owns an isolated PDFium document and page handle

Syntax

function RenderPagesParallel(
  const PageNumbers : array of Integer;
  const Options : TPdfParallelRenderOptions;
  const CancellationToken: IPdfCancellationToken = nil): TPdfParallelRenderReport;

Description

RenderPagesParallel captures the current document once into TPdfRandomAccessStore, removes snapshot encryption, and keeps the source immutable until every worker document closes

An in-memory capture is shared directly without a second byte-array copy, a spilled capture is exposed through one read-only file mapping, and mapping failure falls back to FPDF_LoadCustomDocument block reads from the same thread-safe store

Every worker loads a private temporary copy of the active PDFium binary as an independent module, initialises that module on its worker thread, and reuses its own FPDF_DOCUMENT while loading and closing assigned pages

Module, document, page, progressive-render, and bitmap state never crosses worker boundaries, avoiding unsafe concurrent calls into one PDFium module

PageNumbers uses the public one-based page convention and the returned Results array always matches the request order, even when workers finish out of order or an individual page fails

Each successful result owns a top-down 32-bit pixel buffer with Stride = Width * 4, using BGRA byte order unless reReverseByteOrder requests RGBA

Options

FieldDefaultMeaning
Dpi96Target resolution from more than 0 through 2400 DPI
MaxWorkers00 selects up to four workers, otherwise 1 through 64 bounded by the request count
MaxPixelsPerPage64 MiPixelsRejects a page before allocating an oversized result buffer
MaxTotalOutputBytes512 MiBBounds the sum of retained successful pixel buffers
Rotationro0Applies the same rotation to every request and swaps output dimensions for 90 or 270 degrees
RenderOptions[]Native PDFium render flags including annotations, grayscale, printing, smoothing, and reverse byte order
BackgroundColorclWhiteInitial pixel background before PDFium paints page content

Results

Remarks

Example

uses FPdfAsync;

var
  Options: TPdfParallelRenderOptions;
  Report: TPdfParallelRenderReport;
  I: Integer;
begin
  Options := TPdfParallelRenderOptions.Default;
  Options.Dpi := 150;
  Options.MaxWorkers := 4;
  Options.RenderOptions := [reAnnotations];

  Report := Pdf1.RenderPagesParallel([1, 3, 5, 7], Options, CancelToken);
  for I := 0 to High(Report.Results) do
    if Report.Results[I].Status = pprsSucceeded then
      ConsumeTopDownPixels(Report.Results[I]);
end;

See Also

RenderPage, RenderPageProgressive, RenderTile