Skip to content

Office-Konvertierung

Konvertieren Sie Microsoft-Office-Dokumente (Word, Excel, PowerPoint) in PDF, ohne dass Microsoft Office oder LibreOffice installiert sein muss. PDF Oxide analysiert das OOXML-Format direkt und erzeugt PDF-Ausgabe.

Schnellbeispiel

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)?;

Unterstützte Formate

Format Extension Description
DOCX .docx Word documents — paragraphs, headings, lists, text formatting
XLSX .xlsx, .xls Excel spreadsheets — multi-sheet, auto-sized columns, cell types
PPTX .pptx PowerPoint presentations — slides, titles, text boxes

Word Documents (DOCX)

Word-Dokumente konvertieren und dabei Überschriften, Absätze, Listen und Textformatierung (fett, kursiv, unterstrichen, Farben, Schriftgrößen) beibehalten.

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)?;

From 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
  • Font sizes and colors
  • Numbered and bulleted lists with nesting
  • Metadata extraction (title, author from docProps/core.xml)

Excel Spreadsheets (XLSX)

Tabellenkalkulationen in PDF konvertieren mit automatisch berechneten Spaltenbreiten und Unterstützung mehrerer Blätter. Jedes Blatt wird als separater Abschnitt gerendert.

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 Presentations (PPTX)

Präsentationen in PDF konvertieren. Jede Folie wird zu einer Seite mit extrahierten Titeln und Textfeldern.

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)?;

Configuration (Rust)

Customize page size, margins, and fonts using 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

Feld Typ Standard Beschreibung
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 Default text size in points
line_height f32 1.2 Line height multiplier
include_images bool true Include embedded images

Seite 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

Batch Conversion

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-Referenz

Python — OfficeConverter

Methode Rückgabe Beschreibung
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

Alle Methoden geben ein Pdf-Objekt zurück. Rufen Sie pdf.save("output.pdf") oder pdf.to_bytes() auf, um das Ergebnis zu erhalten.

Rust — OfficeConverter

Methode Rückgabe Beschreibung
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

Verwandte Seiten