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;
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
FillColor — opaque replacement color, default clBlackRemoveIntersectingAnnotations — removes non-redaction annotations whose rectangles overlap a redaction rectangle, default TrueMaxPageObjects — maximum number of top-level page objects scanned across redacted pages, default 1000000PreservePartialObjects — retains supported non-intersecting text, path, and image fragments, default TrueMaxSplitObjects — maximum number of safe fragments created across the operation, default 1000000PreserveComplexObjects — enables bounded Form expansion, solid filled path clipping, and affine image pixel clearing when PreservePartialObjects is also enabled, default TrueMaxFormDepth — maximum nested Form expansion depth, default 32, accepted range 1..64MaxPathPoints — limits segments in an affected path and the cumulative generated path points, default 262144, accepted range 1..1000000MaxImagePixels — cumulative decoded pixels processed for detailed image replacements, default 16777216, accepted range 1..67108864MaxGeometryOperations — cumulative detailed geometry work, including annotation and text scans, path subdivision and clipping, and pixel intersection tests, default 67108864, accepted range 1..1000000000CurveTolerancePdfPoints — page-space cubic flattening tolerance, default 0.01, accepted finite range 0.0001..0.1; path cuts expand by this tolerance plus 0.001 PDF points, so a narrow additional safe margin can be removedThe 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
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
0.001 PDF points; both RGB and alpha are zeroed, then an opaque FillColor overlay covers the redaction rectangle/ActualText or /Alt replacement data, XFA, and optional-content layer semantics including /OCProperties, /OCG, and /OCMD; this method does not rebuild logical structure or preserve those hidden semanticsTr operands, and scn/SCN pattern or special-color-space paint; supported inspected content streams are unfiltered or use a single named /FlateDecode filter256 MiB, individual active object bodies to 64 MiB, total active bodies to 256 MiB, decoded object streams to 64 MiB each and 256 MiB total, and object slots to 1000000; inspected content decoding has additional 32 MiB per-stream and 64 MiB total limits/AF, the /Names tree, native embedded attachments, and file-attachment annotations on redacted pages are removed; arbitrary associated-file entries nested in unrelated structure dictionaries are outside this method's explicit guarantee/Redact annotations exist still produces the sanitized single-revision security profile
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;