Skip to content

Redaction

PDF Oxide supports a two-phase redaction workflow following the PDF specification: first, mark regions for redaction using redaction annotations, then apply the redactions to draw colored overlays that hide the content. This approach gives you a review step before permanently obscuring sensitive information.

Language support. Redaction apply is currently available in Rust, Python, and the WASM/browser build. Node.js, Go, and C# bindings do not yet expose applyPageRedactions / applyAllRedactions; use the Rust CLI or call through WASM if you need redaction from those runtimes.

Redaction Workflow

The standard redaction process has three steps:

  1. Mark – Add redaction annotations to identify content to hide
  2. Review – Inspect marked regions before applying (optional)
  3. Apply – Draw overlays and remove redaction annotations
  4. Save – Write the redacted PDF to disk

Step 1: Add Redaction Annotations

Use the PdfPage annotation API to add redaction annotations that mark regions for removal.

Python

from pdf_oxide import PdfDocument

doc = PdfDocument("confidential.pdf")
page = doc.page(0)

# Find sensitive text and mark it for redaction
for t in page.find_text_containing("SSN"):
    bbox = t.bbox  # (x, y, width, height)
    page.add_highlight(bbox[0], bbox[1], bbox[2], bbox[3], (0.0, 0.0, 0.0))

doc.save_page(page)

Rust

use pdf_oxide::api::Pdf;
use pdf_oxide::writer::RedactAnnotation;
use pdf_oxide::geometry::Rect;

let mut doc = Pdf::open("confidential.pdf")?;
let mut page = doc.page(0)?;

// Mark a specific region for redaction
let redact = RedactAnnotation::new(
    Rect::new(100.0, 700.0, 200.0, 14.0)
);
page.add_annotation(redact);

// Mark all text containing "SSN" for redaction
let sensitive = page.find_text_containing("SSN");
for t in &sensitive {
    let redact = RedactAnnotation::new(t.bbox());
    page.add_annotation(redact);
}

doc.save_page(page)?;

Step 2: Apply Redactions

Once redaction annotations are in place, apply them to draw colored overlays over the marked regions. This step finds all redaction annotations, renders overlays, and removes the redaction annotations.

Apply on a Single Page

doc = PdfDocument("marked.pdf")
doc.apply_page_redactions(0)
doc.save("redacted.pdf")
import { WasmPdfDocument } from "pdf-oxide-wasm";

const doc = new WasmPdfDocument(bytes);
doc.applyPageRedactions(0);
const output = doc.save();
doc.free();
use pdf_oxide::editor::DocumentEditor;

let mut editor = DocumentEditor::open("marked.pdf")?;
editor.apply_page_redactions(0)?;
editor.save("redacted.pdf")?;

Apply on All Pages

doc = PdfDocument("marked.pdf")
doc.apply_all_redactions()
doc.save("redacted.pdf")
import { WasmPdfDocument } from "pdf-oxide-wasm";

const doc = new WasmPdfDocument(bytes);
doc.applyAllRedactions();
const output = doc.save();
doc.free();
let mut editor = DocumentEditor::open("marked.pdf")?;
editor.apply_all_redactions()?;
editor.save("redacted.pdf")?;

Checking Redaction Status

Check if a Page is Marked

doc = PdfDocument("input.pdf")
doc.apply_page_redactions(0)

print(doc.is_page_marked_for_redaction(0))  # True (before save)
let mut editor = DocumentEditor::open("input.pdf")?;
editor.apply_page_redactions(0)?;

assert!(editor.is_page_marked_for_redaction(0));

Cancel Pending Redactions

If you change your mind before saving, unmark a page to cancel the pending redaction.

doc.unmark_page_for_redaction(0)
print(doc.is_page_marked_for_redaction(0))  # False
editor.unmark_page_for_redaction(0);
assert!(!editor.is_page_marked_for_redaction(0));

Complete Redaction Workflow

Python

from pdf_oxide import PdfDocument

doc = PdfDocument("sensitive-report.pdf")

# Step 1: Add redaction annotations via the DOM
for i in range(doc.page_count()):
    page = doc.page(i)

    # Mark SSN patterns
    for t in page.find_text_containing("SSN"):
        bbox = t.bbox
        page.add_highlight(bbox[0], bbox[1], bbox[2], bbox[3], (0.0, 0.0, 0.0))

    # Mark email addresses
    for t in page.find_text_containing("@"):
        bbox = t.bbox
        page.add_highlight(bbox[0], bbox[1], bbox[2], bbox[3], (0.0, 0.0, 0.0))

    doc.save_page(page)

# Step 2: Apply all redactions
doc.apply_all_redactions()

# Step 3: Save the redacted document
doc.save("report-redacted.pdf")

Rust

use pdf_oxide::api::Pdf;
use pdf_oxide::writer::RedactAnnotation;

let mut doc = Pdf::open("sensitive-report.pdf")?;
let count = doc.page_count()?;

// Step 1: Mark regions for redaction
for i in 0..count {
    let mut page = doc.page(i)?;

    // Find and mark sensitive text
    let ssn_matches = page.find_text_containing("SSN");
    for t in &ssn_matches {
        let redact = RedactAnnotation::new(t.bbox());
        page.add_annotation(redact);
    }

    let email_matches = page.find_text_containing("@");
    for t in &email_matches {
        let redact = RedactAnnotation::new(t.bbox());
        page.add_annotation(redact);
    }

    doc.save_page(page)?;
}

// Step 2: Apply redactions
let editor = doc.editor().unwrap();
editor.apply_all_redactions()?;

// Step 3: Save
doc.save("report-redacted.pdf")?;

Full API Reference

DocumentEditor Redaction Methods

Method Returns Description
apply_page_redactions(page) Result<()> Apply redactions on a single page
apply_all_redactions() Result<()> Apply redactions on all pages
is_page_marked_for_redaction(page) bool Check if page has pending redactions
unmark_page_for_redaction(page) () Cancel pending redactions for a page

Python (PdfDocument) Methods

Method Parameters Description
apply_page_redactions(page) page: int Apply redactions on a single page
apply_all_redactions() Apply redactions on all pages
is_page_marked_for_redaction(page) page: int Check redaction status
unmark_page_for_redaction(page) page: int Cancel pending redactions

Important Notes

  • Visual overlay: Redaction draws a colored rectangle over the marked area. The underlying content stream data is visually hidden but may still be present in the file. For complete removal, consider combining redaction with a full rewrite save.
  • Two-phase process: Always add redaction annotations first, then call apply_page_redactions() or apply_all_redactions(). Calling apply without redaction annotations has no effect.
  • Irreversible: Once saved, the visual overlay is permanent. Always work on a copy of the original document.
  • Color: By default, redactions use a black overlay. Use RedactAnnotation with color options for custom overlay colors.