페이지 작업
PDF Oxide는 회전, 미디어 및 크롭 박스 제어, 여백 자르기, 페이지 병합, 추출, 콘텐츠 삭제, 페이지 재정렬 등 페이지 수준 작업의 전체 세트를 제공합니다.
페이지 회전
회전 가져오기
페이지의 현재 회전을 각도(0, 90, 180, 또는 270)로 검색합니다.
from pdf_oxide import PdfDocument
doc = PdfDocument("input.pdf")
rotation = doc.page_rotation(0)
print(f"Page 0 is rotated {rotation} degrees")
use pdf_oxide::editor::DocumentEditor;
let mut editor = DocumentEditor::open("input.pdf")?;
let rotation = editor.get_page_rotation(0)?;
println!("Page 0 is rotated {} degrees", rotation);
회전 설정
특정 페이지의 절대 회전을 설정합니다.
doc = PdfDocument("input.pdf")
doc.set_page_rotation(0, 90) # Rotate page 0 to 90 degrees
doc.save("rotated.pdf")
import { WasmPdfDocument } from "pdf-oxide-wasm";
const doc = new WasmPdfDocument(bytes);
doc.setPageRotation(0, 90);
const output = doc.save();
doc.free();
let mut editor = DocumentEditor::open("input.pdf")?;
editor.set_page_rotation(0, 90)?;
editor.save("rotated.pdf")?;
증분 회전
기존 회전에 회전 증분을 추가합니다.
let mut editor = DocumentEditor::open("input.pdf")?;
// Rotate page 0 by an additional 90 degrees
editor.rotate_page_by(0, 90)?;
editor.save("rotated.pdf")?;
모든 페이지 회전
문서의 모든 페이지에 동일한 회전을 적용합니다.
doc = PdfDocument("input.pdf")
doc.rotate_all_pages(180)
doc.save("flipped.pdf")
import { WasmPdfDocument } from "pdf-oxide-wasm";
const doc = new WasmPdfDocument(bytes);
doc.rotateAllPages(180);
const output = doc.save();
doc.free();
let mut editor = DocumentEditor::open("input.pdf")?;
editor.rotate_all_pages(180)?;
editor.save("flipped.pdf")?;
Media Box와 Crop Box
MediaBox는 전체 물리적 페이지 크기를 정의합니다. CropBox는 표시되고 인쇄되는 영역인 보이는 영역을 정의합니다.
MediaBox 가져오기 및 설정
doc = PdfDocument("input.pdf")
# Get MediaBox: (llx, lly, urx, ury)
box = doc.page_media_box(0)
print(f"MediaBox: {box}")
# Set MediaBox to US Letter (612 x 792 points)
doc.set_page_media_box(0, 0, 0, 612, 792)
doc.save("output.pdf")
import { WasmPdfDocument } from "pdf-oxide-wasm";
const doc = new WasmPdfDocument(bytes);
// Get MediaBox: [llx, lly, urx, ury]
const mediaBox = doc.pageMediaBox(0);
console.log("MediaBox:", mediaBox);
// Set MediaBox to US Letter (612 x 792 points)
doc.setPageMediaBox(0, 0, 0, 612, 792);
const output = doc.save();
doc.free();
let mut editor = DocumentEditor::open("input.pdf")?;
// Get MediaBox as [llx, lly, urx, ury]
let media_box = editor.get_page_media_box(0)?;
println!("MediaBox: {:?}", media_box);
// Set MediaBox
editor.set_page_media_box(0, [0.0, 0.0, 612.0, 792.0])?;
editor.save("output.pdf")?;
CropBox 가져오기 및 설정
doc = PdfDocument("input.pdf")
# Get CropBox (returns None if not set)
crop = doc.page_crop_box(0)
print(f"CropBox: {crop}")
# Set CropBox to crop a 1-inch border (72 points = 1 inch)
doc.set_page_crop_box(0, 72, 72, 540, 720)
doc.save("cropped.pdf")
import { WasmPdfDocument } from "pdf-oxide-wasm";
const doc = new WasmPdfDocument(bytes);
// Get CropBox (null if not set)
const cropBox = doc.pageCropBox(0);
console.log("CropBox:", cropBox);
// Set CropBox to crop a 1-inch border (72 points = 1 inch)
doc.setPageCropBox(0, 72, 72, 540, 720);
const output = doc.save();
doc.free();
let mut editor = DocumentEditor::open("input.pdf")?;
// Get CropBox (None if not explicitly set)
let crop_box = editor.get_page_crop_box(0)?;
println!("CropBox: {:?}", crop_box);
// Set CropBox
editor.set_page_crop_box(0, [72.0, 72.0, 540.0, 720.0])?;
editor.save("cropped.pdf")?;
Crop Margins
A convenience method that sets the CropBox to be inset from the MediaBox by the specified margins on all pages.
doc = PdfDocument("input.pdf")
# Crop 0.5 inch (36pt) from all sides on every page
doc.crop_margins(36, 36, 36, 36)
doc.save("cropped.pdf")
import { WasmPdfDocument } from "pdf-oxide-wasm";
const doc = new WasmPdfDocument(bytes);
// Arguments: left, right, top, bottom (in points)
doc.cropMargins(36, 36, 36, 36);
const output = doc.save();
doc.free();
let mut editor = DocumentEditor::open("input.pdf")?;
// Arguments: left, right, top, bottom (in points)
editor.crop_margins(36.0, 36.0, 36.0, 36.0)?;
editor.save("cropped.pdf")?;
PDF 병합
다른 PDF에서 모든 페이지 병합
다른 PDF의 모든 페이지를 현재 문서 끝에 추가합니다.
use pdf_oxide::editor::DocumentEditor;
let mut editor = DocumentEditor::open("main.pdf")?;
let pages_added = editor.merge_from("appendix.pdf")?;
println!("Added {} pages", pages_added);
editor.save("combined.pdf")?;
특정 페이지 병합
소스 PDF에서 특정 페이지를 선택하여 추가합니다.
let mut editor = DocumentEditor::open("main.pdf")?;
// Merge only pages 0, 2, and 4 from the source
editor.merge_pages_from("source.pdf", &[0, 2, 4])?;
editor.save("selected.pdf")?;
페이지 추출
페이지의 부분 집합을 새 PDF 파일로 추출합니다.
from pdf_oxide import PdfDocument
doc = PdfDocument("document.pdf")
# Extract specific pages to a new file
doc.extract_pages([0, 2, 4], "selected_pages.pdf")
const doc = new WasmPdfDocument(bytes);
// Extract pages to new PDF
const extracted = doc.extractPages([0, 2, 4]);
// extracted is Uint8Array of new PDF
doc.free();
use pdf_oxide::editor::DocumentEditor;
let mut editor = DocumentEditor::open("book.pdf")?;
// Extract pages 0-4 (first 5 pages) to a new file
editor.extract_pages(&[0, 1, 2, 3, 4], "chapter1.pdf")?;
콘텐츠 삭제
페이지의 직사각형 영역을 삭제(화이트아웃)합니다. 지정된 영역 위에 흰색 직사각형을 그려 아래의 콘텐츠를 시각적으로 숨깁니다.
단일 영역 삭제
doc = PdfDocument("input.pdf")
# 영역 삭제: (page, llx, lly, urx, ury)
doc.erase_region(0, 72, 700, 300, 792)
doc.save("erased.pdf")
import { WasmPdfDocument } from "pdf-oxide-wasm";
const doc = new WasmPdfDocument(bytes);
// 영역 삭제: (pageIndex, llx, lly, urx, ury)
doc.eraseRegion(0, 72, 700, 300, 792);
const output = doc.save();
doc.free();
let mut editor = DocumentEditor::open("input.pdf")?;
editor.erase_region(0, [72.0, 700.0, 300.0, 792.0])?;
editor.save("erased.pdf")?;
여러 영역 삭제
doc = PdfDocument("input.pdf")
doc.erase_regions(0, [
(72, 700, 300, 792),
(72, 600, 300, 650),
])
doc.save("erased.pdf")
import { WasmPdfDocument } from "pdf-oxide-wasm";
const doc = new WasmPdfDocument(bytes);
// Pass regions as a flat Float32Array: [llx, lly, urx, ury, ...]
const regions = new Float32Array([
72, 700, 300, 792,
72, 600, 300, 650,
]);
doc.eraseRegions(0, regions);
const output = doc.save();
doc.free();
let mut editor = DocumentEditor::open("input.pdf")?;
editor.erase_regions(0, &[
[72.0, 700.0, 300.0, 792.0],
[72.0, 600.0, 300.0, 650.0],
])?;
editor.save("erased.pdf")?;
보류 중인 삭제 해제
저장 전 페이지의 모든 보류 중인 삭제 작업을 제거합니다.
doc.clear_erase_regions(0)
editor.clear_erase_regions(0);
페이지 재정렬 및 조작
EditableDocument 트레이트는 페이지 조작 메서드를 제공합니다.
페이지 제거
doc = PdfDocument("document.pdf")
doc.delete_page(3)
doc.save("modified.pdf")
const doc = new WasmPdfDocument(bytes);
doc.deletePage(3);
const saved = doc.save();
doc.free();
use pdf_oxide::editor::{DocumentEditor, EditableDocument};
let mut editor = DocumentEditor::open("input.pdf")?;
editor.remove_page(2)?; // Remove page at index 2
editor.save("output.pdf")?;
페이지 이동
doc = PdfDocument("document.pdf")
doc.move_page(5, 1) # Move page from position 5 to position 1
doc.save("reordered.pdf")
let mut editor = DocumentEditor::open("input.pdf")?;
editor.move_page(0, 3)?; // Move page 0 to position 3
editor.save("reordered.pdf")?;
페이지 복제
let mut editor = DocumentEditor::open("input.pdf")?;
let new_index = editor.duplicate_page(0)?; // Duplicate page 0
println!("Duplicate is at index {}", new_index);
editor.save("output.pdf")?;
전체 API 레퍼런스
회전
| 메서드 | 반환값 | 설명 |
|---|---|---|
get_page_rotation(index) |
Result<i32> |
회전 각도 가져오기 |
set_page_rotation(index, degrees) |
Result<()> |
절대 회전 설정 |
rotate_page_by(index, degrees) |
Result<()> |
증분 회전 추가 |
rotate_all_pages(degrees) |
Result<()> |
모든 페이지 회전 |
페이지 박스
| 메서드 | 반환값 | 설명 |
|---|---|---|
get_page_media_box(index) |
Result<[f32; 4]> |
MediaBox 가져오기 |
set_page_media_box(index, box) |
Result<()> |
MediaBox 설정 |
get_page_crop_box(index) |
Result<Option<[f32; 4]>> |
CropBox 가져오기 |
set_page_crop_box(index, box) |
Result<()> |
CropBox 설정 |
crop_margins(left, right, top, bottom) |
Result<()> |
여백으로 모든 페이지 자르기 |
병합 및 추출
| 메서드 | 반환값 | 설명 |
|---|---|---|
merge_from(path) |
Result<usize> |
다른 PDF에서 모든 페이지 병합 |
merge_pages_from(path, pages) |
Result<usize> |
특정 페이지 병합 |
extract_pages(pages, output) |
Result<()> |
새 파일로 페이지 추출 |
콘텐츠 삭제
| 메서드 | 반환값 | 설명 |
|---|---|---|
erase_region(page, rect) |
Result<()> |
영역 하나 삭제 |
erase_regions(page, rects) |
Result<()> |
여러 영역 삭제 |
clear_erase_regions(page) |
() |
보류 중인 삭제 해제 |
페이지 관리 (EditableDocument)
| 메서드 | 반환값 | 설명 |
|---|---|---|
page_count() |
Result<usize> |
페이지 수 |
get_page_info(index) |
Result<PageInfo> |
페이지 크기 및 회전 |
remove_page(index) |
Result<()> |
페이지 제거 |
move_page(from, to) |
Result<()> |
페이지 재정렬 |
duplicate_page(index) |
Result<usize> |
페이지 복제 |
고급 예제: 스캔된 페이지 정규화
use pdf_oxide::editor::{DocumentEditor, EditableDocument};
let mut editor = DocumentEditor::open("scanned.pdf")?;
let count = editor.current_page_count();
for i in 0..count {
// Set all pages to portrait Letter size
editor.set_page_media_box(i, [0.0, 0.0, 612.0, 792.0])?;
// Reset any rotation
editor.set_page_rotation(i, 0)?;
// Apply uniform margins
editor.set_page_crop_box(i, [36.0, 36.0, 576.0, 756.0])?;
}
editor.save("normalized.pdf")?;
관련 페이지
- Editing Overview – opening, metadata, and save workflow
- Text Editing – find and replace text on pages
- Redaction – permanently redact content
- Annotation Editing – add and flatten annotations