PDFium Delphi Component Docs

RenderPageBandedToStream method

Component: TPdf  ·  Unit: PDFium
Encodes the current page band by band into a caller-owned stream as PNG or TIFF without ever allocating a full-page bitmap

Syntax

function RenderPageBandedToStream(Stream: TStream; Width,
  Height: Integer; const StreamOptions: TPdfBandedImageStreamOptions;
  Rotation: TRotation = ro0; Options: TRenderOptions = [];
  Color: TColor = clWhite): TPdfBandedImageReport;

StreamTStream. Caller-owned writable output positioned where the image begins
StreamOptions.FormatpbifPng for compressed 8-bit RGB PNG or pbifTiff for uncompressed little-endian classic TIFF strips
StreamOptions.BandHeightPositive band and TIFF strip height; the default is 256 rows
StreamOptions.CompressionLevelPNG zlib level from 0 through 9; the default is 6 and TIFF ignores it
StreamOptions.MaxOutputBytesHard encoded byte ceiling; zero means unlimited
RotationTRotation. Display rotation applied to the page
OptionsTRenderOptions. Rendering flags
ColorTColor. Background fill applied to each band before rendering
ResultTPdfBandedImageReport. Band counts, encoded rows, peak band bytes, output bytes, completion flag, and the selected format

Description

The method wraps the stream in the requested built-in encoder, TPdfPngBandedImageEncoder or TPdfTiffBandedImageEncoder, and drives the shared banded pipeline of RenderPageBandedToEncoder. The returned report carries the selected Format instead of pbifCustom

The PNG encoder compresses each scanline directly into sequential IDAT chunks, while the TIFF encoder writes one RGB strip per render band and appends its image file directory after the pixel data. Both encoders write forward only and never seek the caller stream

Peak page pixel storage is one Width x BandHeight BGRA bitmap rather than Width x Height. The report exposes the measured PeakBandBytes so exporters can audit the memory policy, and OutputBytes reflects what was actually written to the stream

Use TPdfBandedImageStreamOptions.Default(pbifPng) or Default(pbifTiff) before overriding individual limits; the defaults are BandHeight = 256, CompressionLevel = 6, and MaxOutputBytes = 0

Remarks

A nil stream, a non-positive BandHeight, or a negative MaxOutputBytes raises EPdfError, and pbifCustom is rejected because a built-in PNG or TIFF format is required

When the encoded image would exceed MaxOutputBytes, the write raises EPdfError with the message Encoded image exceeds the output byte budget

Use RenderPageBandedToEncoder with a custom TPdfBandedImageEncoder descendant for any other container format or for external codecs

Example

StreamOptions := TPdfBandedImageStreamOptions.Default(pbifTiff);
StreamOptions.BandHeight := 256;
StreamOptions.MaxOutputBytes := Int64(512) * 1024 * 1024;
Report := Pdf.RenderPageBandedToStream(OutputStream, 4960, 7016,
  StreamOptions);
if not Report.Completed then
  RaiseBandedExportIncomplete;

See Also

RenderPageBandedToEncoder, RenderPageBanded, RenderPage, RenderPageProgressive