Skip to content

Convert Office Documents to PDF

Convert Microsoft Office documents (Word, Excel, PowerPoint) to PDF without Microsoft Office or LibreOffice installed. PDF Oxide parses the OOXML format directly and produces PDF output.

Quick Example

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

Supported Formats

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)

Convert Word documents preserving headings, paragraphs, lists, and text formatting (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)?;

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)

Convert spreadsheets to PDF with auto-calculated column widths and multi-sheet support. Each sheet is rendered as a separate section.

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)

Convert presentations to PDF. Each slide becomes a page with titles and text boxes extracted.

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

Field Type Default Description
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

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

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 Reference

Python — OfficeConverter

Method Returns Description
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

All methods return a Pdf object. Call pdf.save("output.pdf") or pdf.to_bytes() to get the result.

Rust — OfficeConverter

Method Returns Description
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