RenderPageToMonochromeFile

Rendering and printing

Description

Renders a page to a 1-bit monochrome BMP file, the form used for fax, archival and OCR-oriented output, by rendering the page at DPI and down-converting it. Returns 1 when the file is written, or 0 when the file name is empty or the page cannot be rendered.

Syntax

Delphi

Function TPDFlib.RenderPageToMonochromeFile(DPI: Double; Page: Integer; Const FileName: WideString): Integer;

Parameters

DPI is the resolution used to render the page and is further multiplied by the scale set with SetRenderScale; cost grows with its square, because a full colour bitmap is rendered first and held alongside the 1-bit result. Page is the 1-based page number, clamped into 1..PageCount instead of being rejected. FileName is the full path of the BMP file to create, and an empty name is refused before any rendering starts.

Return values

1 when the monochrome bitmap was written to the file. 0 when FileName is empty, when no document is open, when the page could not be rendered, when rendering was aborted, or when the intermediate bitmap came back empty.

Remarks

This is a thin wrapper around RenderPageToMonochromeFileEx with Threshold and Despeckle both 0, which on Windows selects the legacy GDI path: a StretchBlt in HALFTONE mode that dithers the page to one bit, and a fixed 128 cutoff on other platforms. The resulting dot pattern is stable for a given driver but is not a per-pixel threshold, so call the Ex variant with an explicit threshold when the file has to be reproducible for a CCITT or JBIG2 workflow. Rendering goes through the active renderer and honours SetRenderScale, the crop box in effect, the visible optional-content configuration and the engine picked with SelectRenderer; the currently selected page is left alone and no PDF version is involved. Output is an uncompressed BMP, so the file size follows the pixel dimensions directly. A destination that cannot be created raises the platform file-creation exception rather than returning 0, since this function has no return code for a failed write.