MaskRect

Page layout, vector graphics

Description

Paints an opaque rectangle in the given colour over a region of the specified page, covering whatever content lies underneath while leaving the original bytes in place, so RedactRegion is the call to reach for when the data itself has to go. Coordinates follow the current measurement unit and origin, the page selected before the call is restored afterwards, and the function returns 1 on success, or 0 when no document is selected or the page number is invalid.

Syntax

Delphi

Function TPDFlib.MaskRect(Page: Integer; Left, Top, Width, Height: Double; Red, Green, Blue: Double): Integer;

Parameters

Page is the 1-based page number and must lie in 1..PageCount; the page does not have to be the selected one. Left and Top are the coordinates of the rectangle's upper-left corner in the current measurement unit and origin, and Width and Height are its extents in the same unit; the rectangle always grows downward from Top by Height, whichever origin corner is active. Red, Green and Blue are the fill components on a 0..1 scale, where 1 means full intensity, and each component is clamped to that range before it reaches the content stream, so 1.4 is treated as 1 and -0.2 as 0.

Return values

1 when the filled rectangle was appended to the page content. 0 when no document is open or Page is outside 1..PageCount, in which case nothing is painted. A colour that the document refuses does not produce a zero here.

Remarks

The rectangle is appended to the page content stream as one more fill operation, which covers the region visually but leaves the original operators untouched: the text underneath remains selectable, searchable and extractable, and its bytes stay in the file, so this is masking rather than redaction - use RedactRegion when the data itself has to be destroyed. Because the colour is applied through the same code path as SetFillColor, the call also changes the current fill colour that later drawing on the page inherits. In a PDF/X-1a document, or in PDF/X-3 and PDF/X-4 without a DeviceRGB output intent, that colour assignment is refused and LastErrorCode becomes 601, yet the rectangle is still painted with the previous fill colour and the function still returns 1: check LastErrorCode or call SetFillColor separately when colour fidelity matters. The page selected before the call is restored before returning, no PDF version is raised, and the document must be saved for the mask to persist.