Redaction
PDF Oxide는 PDF 사양을 따르는 2단계 교정 워크플로를 제공합니다: 먼저 교정 주석을 사용하여 교정할 영역을 표시한 다음, 교정을 적용하여 콘텐츠를 숨기는 색상 오버레이를 그립니다. 이 접근 방식은 민감한 정보를 영구적으로 가리기 전에 검토 단계를 제공합니다.
교정 워크플로
표준 교정 프로세스는 네 단계로 구성됩니다:
- 표시 – 숨길 콘텐츠를 식별하기 위해 교정 주석 추가
- 검토 – 적용 전 표시된 영역 검사 (선택 사항)
- 적용 – 오버레이를 그리고 교정 주석 제거
- 저장 – 교정된 PDF를 디스크에 저장
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단계: 교정 적용
교정 주석이 배치되면 표시된 영역 위에 색상 오버레이를 그려 적용합니다. 이 단계에서 모든 교정 주석을 찾고, 오버레이를 렌더링하고, 교정 주석을 제거합니다.
단일 페이지에 적용
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")?;
모든 페이지에 적용
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 메서드s
| 메서드 | 반환값 | 설명 |
|---|---|---|
apply_page_redactions(page) |
Result<()> |
단일 페이지에 편집 적용 |
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) 메서드s
| 메서드 | 매개변수 | 설명 |
|---|---|---|
apply_page_redactions(page) |
page: int |
단일 페이지에 편집 적용 |
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 |
중요 사항
- 시각적 오버레이: 교정은 표시된 영역 위에 색상이 있는 직사각형을 그립니다. 기본 콘텐츠 스트림 데이터는 시각적으로 숨겨지지만 파일에 여전히 존재할 수 있습니다. 완전한 제거를 위해 교정과 전체 재작성 저장을 결합하는 것을 고려하세요.
- 2단계 프로세스: 항상 먼저 교정 주석을 추가한 다음
apply_page_redactions()또는apply_all_redactions()를 호출하세요. 교정 주석 없이 적용을 호출하면 효과가 없습니다. - 비가역적: 저장 후 시각적 오버레이는 영구적입니다. 항상 원본 문서의 사본으로 작업하세요.
- 색상: 기본적으로 교정은 검은색 오버레이를 사용합니다. 사용자 정의 오버레이 색상을 위해 색상 옵션이 있는
RedactAnnotation을 사용하세요.
관련 페이지
- Annotation Editing – working with annotations
- Page Operations – content erasure (whiteout) as an alternative
- Text Editing – finding text to redact
- Encryption & Security – restrict access after redaction