PDFium Delphi Component 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

Color = clNone or Color = clDefault selects a transparent background and an alpha-capable PDFium bitmap. Uncovered pixels retain zero alpha independently of the native page background-transparency query, including partially rendered results returned after cancellation; clWhite remains the default opaque background

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

PDFium renders directly into a compatible destination bitmap buffer. Native LCL buffers must also have the expected byte order, channel shifts, line order and stride; other layouts are converted using their actual raw-image description

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