Office 문서를 PDF로 변환
Microsoft Office나 LibreOffice 없이 Microsoft Office 문서(Word, Excel, PowerPoint)를 PDF로 변환합니다. PDF Oxide는 OOXML 형식을 직접 파싱하여 PDF 출력을 생성합니다.
빠른 예제
Python
from pdf_oxide import OfficeConverter
# Auto-detect format from extension
pdf = OfficeConverter.convert("report.docx")
pdf.save("report.pdf")
Rust
use pdf_oxide::converters::office::OfficeConverter;
let converter = OfficeConverter::new();
let pdf_bytes = converter.convert("report.docx")?;
std::fs::write("report.pdf", pdf_bytes)?;
지원 형식
| Format | Extension | 설명 |
|---|---|---|
| DOCX | .docx |
Word 문서 — paragraphs, headings, lists, text formatting |
| XLSX | .xlsx, .xls |
Excel 스프레드시트 — multi-sheet, auto-sized columns, cell types |
| PPTX | .pptx |
PowerPoint 프레젠테이션 — slides, titles, text boxes |
Word 문서 (DOCX)
제목, 단락, 목록, 텍스트 서식을 유지하면서 Word 문서를 변환 (bold, italic, underline, colors, font sizes).
Python
from pdf_oxide import OfficeConverter
pdf = OfficeConverter.from_docx("document.docx")
pdf.save("document.pdf")
Rust
use pdf_oxide::converters::office::OfficeConverter;
let converter = OfficeConverter::new();
let pdf_bytes = converter.convert_docx("document.docx")?;
std::fs::write("document.pdf", pdf_bytes)?;
바이트에서
Python
from pdf_oxide import OfficeConverter
with open("document.docx", "rb") as f:
pdf = OfficeConverter.from_docx_bytes(f.read())
pdf.save("document.pdf")
Rust
let docx_bytes = std::fs::read("document.docx")?;
let converter = OfficeConverter::new();
let pdf_bytes = converter.convert_docx_bytes(&docx_bytes)?;
std::fs::write("document.pdf", pdf_bytes)?;
DOCX Features Supported
- Paragraphs with alignment (left, center, right, justified)
- Headings (Heading 1–9 styles)
- Text formatting: bold, italic, underline, strikethrough
- 글꼴 크기 및 색상
- Numbered and bulleted lists with nesting
- Metadata extraction (title, author from
docProps/core.xml)
Excel 스프레드시트 (XLSX)
자동 계산된 열 너비와 다중 시트 지원으로 스프레드시트를 PDF로 변환합니다. 각 시트는 별도의 섹션으로 렌더링됩니다.
Python
from pdf_oxide import OfficeConverter
pdf = OfficeConverter.from_xlsx("data.xlsx")
pdf.save("data.pdf")
Rust
let converter = OfficeConverter::new();
let pdf_bytes = converter.convert_xlsx("data.xlsx")?;
std::fs::write("data.pdf", pdf_bytes)?;
XLSX Features Supported
- Multi-sheet rendering with sheet titles
- Cell types: strings, integers, floats, booleans, dates, errors
- Automatic column width calculation
- Automatic page breaks when content exceeds available space
PowerPoint 프레젠테이션 (PPTX)
프레젠테이션을 PDF로 변환합니다. 각 슬라이드는 제목과 텍스트 박스가 추출된 페이지가 됩니다.
Python
from pdf_oxide import OfficeConverter
pdf = OfficeConverter.from_pptx("slides.pptx")
pdf.save("slides.pdf")
Rust
let converter = OfficeConverter::new();
let pdf_bytes = converter.convert_pptx("slides.pptx")?;
std::fs::write("slides.pdf", pdf_bytes)?;
구성 (Rust)
OfficeConfig를 사용하여 페이지 크기, 여백, 폰트를 사용자 정의합니다:
use pdf_oxide::converters::office::{OfficeConverter, OfficeConfig};
let config = OfficeConfig::a4(); // A4 page size
let converter = OfficeConverter::with_config(config);
let pdf_bytes = converter.convert_docx("document.docx")?;
OfficeConfig Fields
| Field | 타입 | 기본값 | 설명 |
|---|---|---|---|
page_size |
PageSize |
Letter | Page dimensions |
margins |
Margins |
1 inch all sides | Page margins in points (72pt = 1 inch) |
embed_fonts |
bool |
false |
Whether to embed fonts |
default_font |
String |
"Helvetica" |
Fallback font |
default_font_size |
f32 |
11.0 |
기본값 text size in points |
line_height |
f32 |
1.2 |
Line height multiplier |
include_images |
bool |
true |
Include embedded images |
Page Size Presets
let config = OfficeConfig::letter(); // 8.5 × 11 inches (default)
let config = OfficeConfig::a4(); // 210 × 297 mm
Custom Margins
use pdf_oxide::converters::office::Margins;
let mut config = OfficeConfig::letter();
config.margins = Margins::uniform(36.0); // 0.5 inch margins
config.margins = Margins::none(); // No margins
일괄 변환
Python
from pdf_oxide import OfficeConverter
from pathlib import Path
office_dir = Path("documents/")
output_dir = Path("pdfs/")
output_dir.mkdir(exist_ok=True)
extensions = {".docx", ".xlsx", ".pptx"}
for doc_path in office_dir.iterdir():
if doc_path.suffix.lower() in extensions:
pdf = OfficeConverter.convert(str(doc_path))
pdf.save(str(output_dir / doc_path.with_suffix(".pdf").name))
print(f"Converted: {doc_path.name}")
Rust
use pdf_oxide::converters::office::OfficeConverter;
use std::fs;
let converter = OfficeConverter::new();
for entry in fs::read_dir("documents/")? {
let path = entry?.path();
match path.extension().and_then(|e| e.to_str()) {
Some("docx" | "xlsx" | "pptx") => {
let pdf_bytes = converter.convert(&path)?;
let out = format!("pdfs/{}.pdf", path.file_stem().unwrap().to_str().unwrap());
fs::write(&out, pdf_bytes)?;
println!("Converted: {}", path.display());
}
_ => {}
}
}
API 레퍼런스
Python — OfficeConverter
| 메서드 | 반환값 | 설명 |
|---|---|---|
OfficeConverter.convert(path) |
Pdf |
Auto-detect format and convert |
OfficeConverter.from_docx(path) |
Pdf |
Convert DOCX file |
OfficeConverter.from_docx_bytes(data) |
Pdf |
Convert DOCX from bytes |
OfficeConverter.from_xlsx(path) |
Pdf |
Convert XLSX file |
OfficeConverter.from_xlsx_bytes(data) |
Pdf |
Convert XLSX from bytes |
OfficeConverter.from_pptx(path) |
Pdf |
Convert PPTX file |
OfficeConverter.from_pptx_bytes(data) |
Pdf |
Convert PPTX from bytes |
모든 메서드는 Pdf 객체를 반환합니다. pdf.save("output.pdf") 또는 pdf.to_bytes()를 호출하여 결과를 가져옵니다.
Rust — OfficeConverter
| 메서드 | 반환값 | 설명 |
|---|---|---|
OfficeConverter::new() |
OfficeConverter |
Create with default config |
OfficeConverter::with_config(config) |
OfficeConverter |
Create with custom config |
convert(path) |
Result<Vec<u8>> |
Auto-detect format and convert |
convert_docx(path) |
Result<Vec<u8>> |
Convert DOCX file |
convert_docx_bytes(bytes) |
Result<Vec<u8>> |
Convert DOCX from bytes |
convert_xlsx(path) |
Result<Vec<u8>> |
Convert XLSX file |
convert_xlsx_bytes(bytes) |
Result<Vec<u8>> |
Convert XLSX from bytes |
convert_pptx(path) |
Result<Vec<u8>> |
Convert PPTX file |
convert_pptx_bytes(bytes) |
Result<Vec<u8>> |
Convert PPTX from bytes |
관련 페이지
- Create from Markdown — Convert Markdown text to PDF
- Create from HTML — Convert HTML to PDF
- Create from Images — Convert images to PDF
- Batch Processing — Parallel processing patterns