RenderPageRegionToStream
Rendering and printing
Description
Renders a rectangle on a page to a caller-owned, seekable stream. Choose the raster format, page box, optional-content state and policy for backend differences
Syntax
function TPDFlib.RenderPageRegionToStream(DPI: Double; Page: Integer;
Left, Top, Width, Height: Double; const Options: TPDFlibPageRasterOptions;
Target: TStream; out Info: TPDFlibPageRasterInfo): Integer;
Parameters
| DPI, Page | A positive finite resolution and a 1-based page number |
|---|---|
| Left, Top, Width, Height | A positive rectangle in default PDF user-space points from the top-left of the effective rotated page box. The whole rectangle must lie inside that box |
| Options | A TPDFlibPageRasterOptions value selecting the raster format, page box, optional-content state and rendering policies |
| Target | A caller-owned seekable stream replaced with the encoded image and reset to its start on success |
| Info | An output TPDFlibPageRasterInfo receiving the raster geometry and effective rendering choices |
Supply a positive finite resolution, a 1-based page, and a positive rectangle measured in default PDF user-space points from the top-left of the effective rotated page box. The whole rectangle must lie inside that box. The library rounds the left and top down and the right and bottom up to cover the requested region
TPDFlibPageRasterOptions
| Format | 0 BMP, 1 JPEG, 5 PNG, 6 GIF, 7 RGB TIFF, 10 Group 4 TIFF. The format field controls the bytes written to either type of destination |
|---|---|
| BackgroundMode | PDF_TILE_BACKGROUND_WHITE (0), PDF_TILE_BACKGROUND_TRANSPARENT (1, color-key transparency for PNG), or PDF_TILE_BACKGROUND_CUSTOM (2). Non-white modes use BackgroundColor |
| CropType | 0 uses the instance setting. Values 1 through 5 request MediaBox, CropBox, BleedBox, TrimBox or ArtBox. The report shows the resolved page box when the requested box is absent |
| OCGMode | PDF_RASTER_OCG_BACKEND_DEFAULT (0) uses the backend's default. PDF_RASTER_OCG_VIEW (1) uses the current screen visibility and PDF_RASTER_OCG_PRINT (2) uses the print visibility |
| Policy | PDF_RASTER_POLICY_REPORT (0) allows defaults and reports the effective choices. PDF_RASTER_POLICY_STRICT (1) rejects a page box or explicitly requested optional-content mode that cannot be honored. PDF_RASTER_POLICY_BUILTIN_FALLBACK (2) uses the built-in renderer when PDFium cannot honor the requested box or explicit optional-content mode |
| DPIMode | PDF_RASTER_DPI_DEFAULT (0) uses the original 1/72-inch scale for PDF coordinates. PDF_RASTER_DPI_PHYSICAL (1) sizes pixels from the page's /UserUnit and keeps the same coordinate system for the region rectangle |
Results
Info reports the requested and effective renderer, requested and effective box, requested and effective optional-content mode, whole-page dimensions, output format, and exclusive pixel bounds in the effective page raster. Page dimensions in points are in default PDF user space
In physical mode the report's UserUnit is the applied scale from the page, or 1 when the entry is absent. RasterDPI includes the page unit. OutputDPI is the density before applying the page unit and is used by formats with a density field. Both include the instance render scale
The built-in path and Cairo on Windows can use screen or print visibility. On non-Windows platforms the tile implementation uses the built-in path. PDFium uses the CropBox with the usual MediaBox fallback and reports backend-default optional content. An explicit built-in fallback applies to the current call and keeps the instance's selected renderer
With PDFium selected, physical mode uses the built-in renderer under the report and fallback policies. The strict policy rejects that combination. Use RenderPageToStreamEx for a whole page on the same pixel grid
Return values
Returns 1 when the stream receives the image and is reset to the start. Returns 0 for invalid geometry, a rejected policy or a renderer failure. Policy and geometry rejection occur before the destination is written
Example
Options := Default(TPDFlibPageRasterOptions);
Options.Format := PDF_RENDER_PNG;
Options.CropType := 1;
Options.OCGMode := PDF_RASTER_OCG_PRINT;
Options.Policy := PDF_RASTER_POLICY_BUILTIN_FALLBACK;
if Lib.RenderPageRegionToStream(144, 1, 12, 12, 180, 90, Options, Image, Info) = 1 then
Writeln(Info.PixelBounds.Right - Info.PixelBounds.Left);
See also RenderPageRegionToFileEx, RenderPageTileToStreamEx and GetRenderCapabilities