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

Defaults enable PreservePartialObjects and PreserveComplexObjects together to keep supported safe geometry; this resource-limited profile reconstructs retained text fragments, clips solid-filled paths and clears intersecting affine-image pixels

If there is any redaction annotation, the detailed profile expands every Form XObject instance on all pages, including unredacted ones, before applying cuts; composed instance transforms allow the original shared Form streams to be pruned afterwards

Set PreservePartialObjects := False to remove entire intersecting objects, or leave it enabled and use PreserveComplexObjects := False for simpler text, axis-aligned rectangle and axis-aligned image fragmentation; all three profiles run the source safety checks

The method removes redaction annotations, optionally removes other intersecting annotations, drops file-attachment annotations on redacted pages and deletes native embedded attachments; the sanitised rewrite strips catalog /AF, active content, forms, metadata and unreachable objects

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

Output contains one clean revision without earlier revisions, and the loaded source stays as it was; unsupported source semantics or detailed geometry abort the operation instead of yielding partial redaction

Options

The detailed profile validates and uses the Form, path, image, geometry and tolerance settings above; none raises the separate source-inspection allowances

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 processing adds ExpandedFormCount, ScannedFormChildCount, FlattenedCurveCount, GeneratedPathPointCount, MaskedImageCount, ScannedImagePixelCount, MaskedImagePixelCount, PixelIntersectionTestCount and GeometryOperationCount; successful processing records the chosen tolerance in CurveTolerancePdfPoints

ScannedFormChildCount includes every native object visited during expansion, including root Form instances; GeneratedPathPointCount includes intermediate clipping points and flattened-curve points alike

MaskedImagePixelCount counts pixels cleared in every colour and alpha sample; PreservedFragmentCount counts replacement objects rather than pixels or contours, and failed processing may leave partial counters without 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