PDFium Delphi Component Docs

RenderPageBandedToEncoder method

Component: TPdf  ·  Unit: PDFium
Renders the current page in clipped horizontal bands and forwards every band bitmap to a caller-supplied banded image encoder

Syntax

function RenderPageBandedToEncoder(Width, Height, BandHeight: Integer;
  Encoder: TPdfBandedImageEncoder; Rotation: TRotation = ro0;
  Options: TRenderOptions = []; Color: TColor = clWhite): TPdfBandedImageReport;

Width, HeightInteger. Size of the full page image in pixels, as if it were rendered in one piece
BandHeightInteger. Height of each band in pixels. The last band is shorter when Height is not a multiple of it
EncoderTPdfBandedImageEncoder. Caller-owned encoder instance that receives the band stream
RotationTRotation. Display rotation applied to the page: ro0, ro90, ro180, or ro270
OptionsTRenderOptions. Rendering flags
ColorTColor. Background fill applied to each band before rendering
ResultTPdfBandedImageReport. Band counts, encoded rows, peak band bytes, output bytes, and completion flag

Description

The method drives the same banding loop as RenderPageBanded, but instead of an application callback it pushes every freshly rendered Width x band-height bitmap through an internal bridge into the three virtual methods of the caller-supplied encoder: BeginImage(Width, Height) runs first, WriteBand(BandIndex, BandTopY, Bitmap) receives one call per band from top to bottom, and EndImage(Completed) closes the image

BandIndex is zero-based and BandTopY is the y-offset of the band top in full-page pixels, which is what a strip writer needs to place the rows in an output file. The bitmap belongs to the render loop and is freed right after WriteBand returns, so an encoder that needs to keep the pixels has to copy them

WriteBand returns True to continue or False to cancel the remaining bands cleanly. EndImage(True) is called only when every requested row was encoded; a cancelled or failed run receives EndImage(False), with exceptions from that failure path suppressed

The returned report carries Format = pbifCustom, the number of bands rendered and accepted in BandsRendered and BandsEncoded, accepted rows in RowsEncoded, the largest band bitmap as Width x band height x 4 bytes in PeakBandBytes, the value of Encoder.GetBytesWritten in OutputBytes, and Completed = True exactly when RowsEncoded = Height

Peak page pixel storage stays at one band bitmap, so posters and engineering drawings can be exported at print resolution without ever allocating the full destination image

Remarks

Passing a nil encoder, non-positive dimensions, or a non-positive band height raises EPdfError

The product of Width and Min(BandHeight, Height) must stay within one quarter of the addressable Integer range, otherwise EPdfError reports that the band buffer exceeds the addressable size

Override GetBytesWritten in the encoder descendant to report encoder-specific output telemetry into OutputBytes; the base implementation returns 0

Example

type
  TRawStripEncoder = class(TPdfBandedImageEncoder)
  public
    procedure BeginImage(Width, Height: Integer); override;
    function WriteBand(BandIndex, BandTopY: Integer;
      Bitmap: TBitmap): Boolean; override;
    procedure EndImage(Completed: Boolean); override;
  end;

Encoder := TRawStripEncoder.Create;
try
  Report := Pdf.RenderPageBandedToEncoder(4960, 7016, 512, Encoder);
  LogBandedExport(Report.BandsEncoded, Report.PeakBandBytes);
finally
  Encoder.Free;
end;

See Also

RenderPageBanded, RenderPageBandedToStream, RenderPage, RenderTile