Table of Contents

Class PdfRedactor

Namespace
LMKit.Document.Pdf
Assembly
LM-Kit.NET.dll

Permanently removes content from PDF documents. Unlike drawing a black rectangle over content, redaction deletes the underlying data: text glyphs are removed from content streams, image pixels are scrubbed and re-encoded, vector graphics are trimmed, intersecting annotations are deleted, and content nested inside Form XObjects is processed per instance. The removed content cannot be recovered from the output file by text extraction, raw stream inspection, or rendering.

public static class PdfRedactor
Inheritance
PdfRedactor
Inherited Members

Examples

Example 1: Redact every occurrence of a name.

using LMKit.Document.Pdf;

var request = new PdfRedactionRequest(); request.SearchTerms.Add("John Doe");

var report = PdfRedactor.RedactToFile("contract.pdf", "contract_redacted.pdf", request); Console.WriteLine($"Matches: {report.SearchMatches}, glyphs removed: {report.RemovedGlyphs}");

Example 2: Redact a fixed region in memory.

using LMKit.Document.Pdf;
using LMKit.Graphics.Geometry;

var request = new PdfRedactionRequest(); request.Areas.Add(new PdfRedactionArea(pageIndex: 0, Rectangle.FromSize(left: 72, top: 90, width: 220, height: 30)));

byte[] source = File.ReadAllBytes("report.pdf"); PdfRedactionResult result = PdfRedactor.RedactToBytes(source, request); File.WriteAllBytes("report_redacted.pdf", result.Data);

Remarks

Marking. A PdfRedactionRequest describes what to remove: explicit page areas, text search terms (every match is redacted), and optionally the document's pre-existing /Redact annotations, for interoperability with files marked in other tools.

Surviving content is untouched. Text removal works at glyph granularity: glyphs outside the redacted areas keep their exact positions. Shared resources (a Form XObject or image reused by other pages) are cloned before editing so only the targeted instance changes.

Input modes. File paths, raw bytes, streams and pre-built Attachment objects are accepted, each with RedactToFile, RedactToStream and RedactToBytes variants in synchronous and asynchronous forms. All variants return a PdfRedactionReport describing what was removed.

Methods

RedactToBytes(Attachment, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Redacts the PDF carried by attachment and returns the redacted bytes together with the report.

RedactToBytes(byte[], PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Redacts in-memory PDF bytes and returns the redacted bytes together with the report.

RedactToBytes(Stream, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Redacts the PDF read from inputStream and returns the redacted bytes together with the report.

RedactToBytes(string, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Redacts the PDF at inputPath and returns the redacted bytes together with the report.

RedactToBytesAsync(Attachment, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Asynchronously redacts the PDF carried by attachment and returns the redacted bytes together with the report.

RedactToBytesAsync(byte[], PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Asynchronously redacts in-memory PDF bytes and returns the redacted bytes together with the report.

RedactToBytesAsync(Stream, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Asynchronously redacts the PDF read from inputStream and returns the redacted bytes together with the report.

RedactToBytesAsync(string, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Asynchronously redacts the PDF at inputPath and returns the redacted bytes together with the report.

RedactToFile(Attachment, string, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Redacts the PDF carried by attachment and writes the result to outputPath.

RedactToFile(byte[], string, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Redacts in-memory PDF bytes and writes the result to outputPath.

RedactToFile(Stream, string, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Redacts the PDF read from inputStream and writes the result to outputPath.

RedactToFile(string, string, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Redacts the PDF at inputPath and writes the result to outputPath.

RedactToFileAsync(Attachment, string, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Asynchronously redacts the PDF carried by attachment and writes the result to outputPath.

RedactToFileAsync(byte[], string, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Asynchronously redacts in-memory PDF bytes and writes the result to outputPath.

RedactToFileAsync(Stream, string, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Asynchronously redacts the PDF read from inputStream and writes the result to outputPath.

RedactToFileAsync(string, string, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Asynchronously redacts the PDF at inputPath and writes the result to outputPath.

RedactToStream(Attachment, Stream, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Redacts the PDF carried by attachment and writes the result to outputStream.

RedactToStream(byte[], Stream, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Redacts in-memory PDF bytes and writes the result to outputStream.

RedactToStream(Stream, Stream, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Redacts the PDF read from inputStream and writes the result to outputStream.

RedactToStream(string, Stream, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Redacts the PDF at inputPath and writes the result to outputStream.

RedactToStreamAsync(Attachment, Stream, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Asynchronously redacts the PDF carried by attachment and writes the result to outputStream.

RedactToStreamAsync(byte[], Stream, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Asynchronously redacts in-memory PDF bytes and writes the result to outputStream.

RedactToStreamAsync(Stream, Stream, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Asynchronously redacts the PDF read from inputStream and writes the result to outputStream.

RedactToStreamAsync(string, Stream, PdfRedactionRequest, PdfRedactionOptions, CancellationToken)

Asynchronously redacts the PDF at inputPath and writes the result to outputStream.

Share