PDFiumVCL Docs

RenderPageProgressive method

Component: TPdf  ·  Unit: PDFium
Cancellable variant of RenderPage that drives PDFium's progressive rendering loop and polls an IPdfCancellationToken between iterations so long high-DPI renders can abort mid-page instead of blocking until completion.

Syntax

function RenderPageProgressive(
  Bitmap : TBitmap;
  Left, Top, Width, Height: Integer;
  const AToken : IPdfCancellationToken;
  Rotation : TRotation = ro0;
  Options : TRenderOptions = [];
  Color : TColor = clWhite): TPdfProgressiveStatus;

Description

RenderPageProgressive renders the current page into the supplied Bitmap using PDFium's FPDF_RenderPageBitmap_Start + FPDF_RenderPage_Continue loop. Between iterations, PDFium's IFSDK_PAUSE callback polls AToken.IsCancelled — when the application has cancelled, the loop unwinds cleanly and the bitmap holds the partial work done so far.

The same zero-copy fast path introduced in v1.21.0 applies: PDFium renders directly into the destination TBitmap's DIB buffer instead of staging through an internal buffer. A legacy per-scanline fallback exists for the unlikely case where the destination DIB cannot be wrapped.

The return value identifies how the render finished:

Pass AToken = nil to render to completion without ever pausing. In that case the function still pumps FPDF_RenderPage_Continue until DONE but never returns prsCancelled. This is useful when the caller wants the progressive loop's intermediate redraw points (a custom OnPaint that mirrors the in-progress bitmap) but does not need cancellation.

Remarks

Example

uses FPdfAsync;

var
  Bitmap: TBitmap;
  Status: TPdfProgressiveStatus;
begin
  Bitmap := TBitmap.Create;
  try
    Bitmap.PixelFormat := pf32bit;
    Bitmap.SetSize(2480, 3508); // A4 @ 300 DPI
    Status := Pdf1.RenderPageProgressive(Bitmap,
      0, 0, Bitmap.Width, Bitmap.Height,
      CancelToken, ro0, [reAnnotations]);
    case Status of
      prsDone: SaveBitmap(Bitmap);
      prsCancelled: Log.Add('Cancelled mid-page');
      prsFailed: Log.Add('PDFium FPDF_RENDER_FAILED');
    end;
  finally
    Bitmap.Free;
  end;
end;

See Also

RenderPage, RenderTile