Schwärzung
PDF Oxide unterstützt einen zweiphasigen Schwärzungs-Workflow gemäß der PDF-Spezifikation: Zunächst werden Bereiche mit Schwärzungsannotationen markiert, dann werden die Schwärzungen angewendet, um farbige Überlagerungen zu zeichnen, die den Inhalt verbergen. Dieser Ansatz gibt Ihnen einen Überprüfungsschritt, bevor sensible Informationen dauerhaft unkenntlich gemacht werden.
Schwärzungs-Workflow
Der Standard-Schwärzungsprozess hat drei Schritte:
- Mark – Add redaction annotations to identify content to hide
- Review – Inspect marked regions before applying (optional)
- Apply – Draw overlays and remove redaction annotations
- Save – Write the redacted PDF to disk
Schritt 1: Schwärzungsannotationen hinzufügen
Verwenden Sie die PdfPage-Anmerkungen-API, um Schwärzungsannotationen hinzuzufügen, die Bereiche zur Entfernung markieren.
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)?;
Schritt 2: Schwärzungen anwenden
Sobald Schwärzungsannotationen vorhanden sind, wenden Sie sie an, um farbige Überlagerungen über die markierten Bereiche zu zeichnen. Dieser Schritt findet alle Schwärzungsannotationen, rendert Überlagerungen und entfernt die Schwärzungsannotationen.
Auf einer einzelnen Seite anwenden
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")?;
Auf allen Seiten anwenden
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")?;
Schwärzungsstatus prüfen
Prüfen, ob eine Seite markiert ist
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));
Ausstehende Schwärzungen abbrechen
Wenn Sie Ihre Meinung vor dem Speichern ändern, heben Sie die Markierung einer Seite auf, um die ausstehende Schwärzung abzubrechen.
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));
Vollständiger Schwärzungs-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")?;
Vollständige API-Referenz
DocumentEditor-Schwärzungsmethoden
| Methode | Rückgabe | Beschreibung |
|---|---|---|
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 |
Prüfen ob Seite ausstehende Schwärzungen hat |
unmark_page_for_redaction(page) |
() |
Cancel pending redactions for a page |
Python (PdfDocument)-Methoden
| 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 |
Wichtige Hinweise
- 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()orapply_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
RedactAnnotationwith color options for custom overlay colors.
Verwandte Seiten
- Anmerkungen-Bearbeitung – mit Annotationen arbeiten
- Seitenoperationen – Inhaltslöschung (Weißen) als Alternative
- Textbearbeitung – zu schwärzenden Text finden
- Verschlüsselung & Sicherheit – Zugriff nach Schwärzung einschränken