PDFium Delphi Component Docs

SaveAsRedacted method

Component: TPdf  ·  Unit: PDFium
Applies PDF redaction annotations to an isolated snapshot and writes a clean single-revision result without modifying the loaded document

Syntax

function SaveAsRedacted(Stream: TStream;
  const Options: TPdfRedactionOptions;
  out Report: TPdfRedactionReport): Boolean; overload;

function SaveAsRedacted(const FileName: string;
  const Options: TPdfRedactionOptions;
  out Report: TPdfRedactionReport): Boolean; overload;

Description

SaveAsRedacted captures the current document into an isolated random-access snapshot, opens that snapshot as a separate TPdf, and processes every /Redact annotation rectangle

The default options enable both PreservePartialObjects and PreserveComplexObjects to retain supported safe geometry; this bounded profile rebuilds text from retained character fragments, clips solid filled paths, and clears intersecting pixels in affine images

When any redaction annotation exists, the detailed profile expands every Form XObject instance on every page, including unredacted pages, before applying redactions; instance transforms are composed and original shared Form streams can then be removed by resource pruning

Set PreservePartialObjects := False to remove whole intersecting objects, or keep it enabled and set PreserveComplexObjects := False to use the simpler text, axis-aligned rectangle, and axis-aligned image fragmentation profile; source safety checks apply to all three profiles

The method removes all redaction annotations, optionally removes other intersecting annotations, removes file-attachment annotations on redacted pages, deletes native embedded attachments, and runs the sanitized rewrite with catalog /AF, active content, forms, metadata, and unreachable objects stripped

After page content is regenerated, precise resource pruning scans page, Form XObject, pattern, appearance, inherited, and nested resource scopes and removes only unused names before unreachable objects are discarded

The output has one clean revision without earlier document revisions, while the loaded source document remains unchanged; unsupported source semantics or unsupported detailed geometry abort the operation rather than producing a partially redacted result

Options

The Form, path, image, geometry, and tolerance options above are validated and used by the detailed profile; they do not raise the independent source inspection budgets

Report

TPdfRedactionReport returns RedactionCount, RedactedPageCount, ScannedObjectCount, RemovedObjectCount, RemovedAnnotationCount, RemovedAttachmentCount, OverlayCount, SplitTextObjectCount, SplitPathObjectCount, SplitImageObjectCount, PreservedFragmentCount, the byte counts, nested SanitiseReport and ResourcePruneReport, Succeeded, and ErrorMessage

Detailed work adds ExpandedFormCount, ScannedFormChildCount, FlattenedCurveCount, GeneratedPathPointCount, MaskedImageCount, ScannedImagePixelCount, MaskedImagePixelCount, PixelIntersectionTestCount, and GeometryOperationCount; CurveTolerancePdfPoints records the configured tolerance after successful processing

ScannedFormChildCount counts native objects visited during expansion, including root Form instances, and GeneratedPathPointCount includes intermediate clipping points as well as flattened curve points

MaskedImagePixelCount counts pixels whose complete color and alpha samples were cleared, while PreservedFragmentCount counts replacement objects rather than individual retained pixels or polygon contours; processing counters on failure can be partial and do not imply a committed output

Security boundary

Example

var
  Options: TPdfRedactionOptions;
  Report: TPdfRedactionReport;
begin
  Options := TPdfRedactionOptions.Default;
  Options.FillColor := clBlack;
  if not Pdf1.SaveAsRedacted('C:\redacted.pdf', Options, Report) then
    raise Exception.Create(Report.ErrorMessage);
end;

See Also

SaveAsSanitised, SaveAsReachable, CreateAnnotation, FPdfRedaction geometry helpers