墨消し
PDF Oxide は PDF 仕様に従った2フェーズの墨消しワークフローをサポートします: まず墨消しアノテーションを使って墨消し領域をマークし、次に墨消しを適用してコンテンツを隠すカラーオーバーレイを描画します。 このアプローチにより、機密情報を永久に隠す前にレビュー手順が得られます。
墨消し Workflow
標準的な墨消しプロセスは3つのステップで構成されます:
- 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
ステップ 1: 墨消しアノテーションの追加
PdfPageアノテーションAPIを使用して、削除対象領域をマークする墨消しアノテーションを追加します。
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)?;
ステップ 2: 墨消しの適用
墨消しアノテーションを配置したら、それらを適用してマーク領域にカラーオーバーレイを描画します。このステップではすべての墨消しアノテーションを検出し、オーバーレイをレンダリングし、墨消しアノテーションを削除します。
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")?;
墨消しステータスの確認
ページがマークされているか確認
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));
保留中の墨消しのキャンセル
保存前に考えが変わった場合、ページのマークを解除して保留中の墨消しをキャンセルします。
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));
墨消しワークフロー(完全版)
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: すべての墨消しを適用
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")?;
完全な API リファレンス
DocumentEditor Redaction Methods
| Method | Returns | 説明 |
|---|---|---|
apply_page_redactions(page) |
Result<()> |
単一ページに墨消しを適用 |
apply_all_redactions() |
Result<()> |
Apply redactions on all pages |
is_page_marked_for_redaction(page) |
bool |
ページに保留中の墨消しがあるか確認 |
unmark_page_for_redaction(page) |
() |
ページの保留中の墨消しをキャンセル |
Python (PdfDocument) Methods
| Method | Parameters | 説明 |
|---|---|---|
apply_page_redactions(page) |
page: int |
単一ページに墨消しを適用 |
apply_all_redactions() |
– | Apply redactions on all pages |
is_page_marked_for_redaction(page) |
page: int |
墨消しステータスを確認 |
unmark_page_for_redaction(page) |
page: int |
保留中の墨消しをキャンセル |
重要な注意事項
- 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.
関連ページ
- Annotation Editing – アノテーションの操作
- Page Operations – 代替としてのコンテンツ消去(ホワイトアウト)
- Text Editing – 墨消しするテキストの検索
- Encryption & Security – 墨消し後のアクセスを制限