RedactRegion
Page manipulation
Requires the Enterprise edition. In Delphi, C++Builder and Lazarus code create the library as TPDFlibEnterprise (unit PDFlibEnterprise); the Enterprise DLL and ActiveX builds provide it unchanged. Other editions keep the method, which returns 0, an empty string or False and sets LastErrorCode to 900 (PDFLIB_ERROR_ENTERPRISE_REQUIRED)
Description
Truly removes text, vector paths, shadings and images whose painted area intersects the rectangle, by editing the page content stream so the underlying glyphs, vectors, and image bytes are gone and cannot be recovered. This is fundamentally different from MaskRect, which only paints an opaque rectangle on top of the content (the original bytes remain and can be extracted)
After a redaction the document is always saved in full: the save drops the objects the redaction left unreferenced, and an incremental save is refused, because it would keep the earlier revision, and the removed data with it, in the file
For each content layer and nested Form XObject the method parses the stream and tracks the graphics state. Optional behaviours controlled by Options: stamp a black fill box over the region, and emit a standard /Subtype /Redact annotation
- Text is measured glyph by glyph from the page fonts: the full text matrix, leading, character and word spacing, horizontal scaling, rise, glyph widths and the CMap of composite fonts. Only the glyphs whose box meets the region are removed; the rest of the string stays and keeps its position through a TJ adjustment, including the line move of the ' and " operators
- When a font cannot be measured, the whole string is removed if a one-em-per-byte estimate meets the region, so unmeasured text errs towards removal
- Glyph height comes from the font descriptor Ascent and Descent when present
- An image XObject that meets the region loses only the covered pixels: raw, Flate, LZW, RunLength, ASCIIHex, ASCII85, DCT (JPEG), JPX (JPEG 2000), JBIG2, and CCITT Group 3/4 streams are decoded to samples, the covered pixels are overwritten with black (or the transparent bit for an
/ImageMaskstencil mask, respecting/Decode [0 1]and/Decode [1 0]polarity), and the image is re-encoded with Flate; inline images (BI … EI) and undecodable streams are removed whole. An image that another page or placement also draws is changed through a private copy - A shading painted with sh is removed when its clip meets the region, or when the clip is unknown
- Annotations whose Rect meets the region are removed, except pending /Redact annotations; a form widget there also takes its field value with it, so the covered data does not survive in the form
- A Form XObject that another page, or another placement on the same page, also draws is redacted through a private copy for this placement; a Form used only here is edited in place so no unredacted copy remains in the file
- With Options 0 the black box is drawn once, on top of the remaining page content
Limitations: path and image bounds use the bounding box of the transformed geometry, which is conservative for rotated or sheared transforms
Syntax
Delphi
Function TPDFlib.RedactRegion(Page: Integer; Left, Top, Width, Height: Double; Options: Integer): Integer; Virtual;ActiveX
Function PDFlib::RedactRegion(Page As Long, Left As Double, Top As Double, Width As Double, Height As Double, Options As Long) As LongDLL
int DLRedactRegion(int InstanceID, int Page, double Left, double Top, double Width, double Height, int Options);
Parameters
| Page | The 1-based page number |
|---|---|
| Left, Top | Top-left corner of the region in current measurement units (top-left origin) |
| Width, Height | Region size in current measurement units |
| Options | 0 = remove + black fill + Redact annotation; 1 = remove only; 2 = remove + Redact annotation (no fill) |
Return values
| >= 0 | The number of instruction ranges removed across all content layers (0 means nothing intersected) |
|---|