MCPcopy Index your code
hub / github.com/developer0hye/office2pdf

github.com/developer0hye/office2pdf @v0.6.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.6.0 ↗ · + Follow
2,484 symbols 8,011 edges 166 files 391 documented · 16%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

office2pdf

CI crates.io docs.rs License

Pure-Rust library and CLI for converting DOCX, XLSX, and PPTX files to PDF.

No LibreOffice, no Chromium, no Docker — just a single binary powered by Typst.

Features

  • DOCX — paragraphs, inline formatting (bold/italic/underline/color), tables, images, drawing shapes, ordered/nested lists, syntax-highlighted code, headers/footers, page setup
  • PPTX — slides, text boxes, shapes, tables (with theme-based table styles), images, slide masters, speaker notes, gradient backgrounds, shadow/reflection effects
  • XLSX — sheets, cell formatting, merged cells, column widths, row heights, conditional formatting (DataBar, IconSet)
  • PDF/A-2b — archival-compliant output via --pdf-a
  • Embedded font extraction — fonts embedded in PPTX/DOCX are automatically extracted, deobfuscated, and used during conversion
  • macOS Office font auto-discovery — PowerPoint/Word/Excel bundled fonts and Office cloud font caches are searched automatically
  • WASM — runs in browsers and Node.js via WebAssembly (optional wasm feature)
  • Zero external dependencies — runs as a standalone executable

Installation

Library

[dependencies]
office2pdf = "0.4"

CLI

cargo install office2pdf-cli

Quick Start

As a library

// Simple one-liner
let result = office2pdf::convert("report.docx").unwrap();
std::fs::write("report.pdf", &result.pdf).unwrap();

// With options
use office2pdf::config::{ConvertOptions, PaperSize};

let options = ConvertOptions {
    paper_size: Some(PaperSize::A4),
    ..Default::default()
};
let result = office2pdf::convert_with_options("slides.pptx", &options).unwrap();
std::fs::write("slides.pdf", &result.pdf).unwrap();

// In-memory conversion
use office2pdf::config::Format;

let docx_bytes = std::fs::read("report.docx").unwrap();
let result = office2pdf::convert_bytes(
    &docx_bytes,
    Format::Docx,
    &ConvertOptions::default(),
).unwrap();
std::fs::write("report.pdf", &result.pdf).unwrap();

CLI

# Single file
office2pdf report.docx

# Explicit output path
office2pdf report.docx -o output.pdf

# Batch conversion
office2pdf *.docx --outdir pdfs/

# With options
office2pdf slides.pptx --paper a4 --landscape
office2pdf spreadsheet.xlsx --sheets "Sheet1,Summary"
office2pdf document.docx --pdf-a
office2pdf report.docx --font-path /usr/share/fonts/custom

On macOS, office2pdf automatically searches Microsoft Office app fonts and local Office font caches before falling back to regular system fonts. --font-path is only needed as an override for custom local fonts.

WASM (Browser / Node.js)

Build with wasm-pack:

wasm-pack build crates/office2pdf --target web --features wasm

Use from JavaScript:

import init, { convertDocxToPdf, convertToPdf } from './pkg/office2pdf.js';

await init();

const docxBytes = new Uint8Array(await file.arrayBuffer());
const pdfBytes = convertDocxToPdf(docxBytes);

// Or use the generic API with a format string
const pdfBytes2 = convertToPdf(xlsxBytes, "xlsx");

Available functions: convertToPdf(data, format), convertDocxToPdf(data), convertPptxToPdf(data), convertXlsxToPdf(data).

CLI Options

Flag Description
-o, --output <PATH> Output file path (single input only)
--outdir <DIR> Output directory for batch conversion
--paper <SIZE> Paper size: a4, letter, legal
--landscape Force landscape orientation
--pdf-a Produce PDF/A-2b compliant output
--sheets <NAMES> XLSX sheet filter (comma-separated)
--slides <RANGE> PPTX slide range (e.g. 1-5 or 3)
--font-path <DIR> Additional font directory override (repeatable)

Supported Formats

Format Status Key Features
DOCX Supported Text, tables, images, drawing shapes, lists, code highlighting, headers/footers, page setup
PPTX Supported Slides, text boxes, shapes, tables, images, masters, gradients, effects
XLSX Supported Sheets, formatting, merged cells, column/row sizing, conditional formatting

License

Licensed under Apache License, Version 2.0.

Extension points exported contracts — how you extend this code

Positioned (Interface)
Common interface for elements with position and dimensions. [3 implementers]
crates/office2pdf/src/ir/mod.rs
Parser (Interface)
Trait for parsing an input file format into the IR. [3 implementers]
crates/office2pdf/src/parser/mod.rs

Core symbols most depended-on inside this repo

parse
called by 386
crates/office2pdf/src/parser/pptx.rs
push
called by 308
crates/office2pdf/src/parser/pptx.rs
generate_typst
called by 232
crates/office2pdf/src/render/typst_gen.rs
is_empty
called by 114
crates/office2pdf/src/parser/embedded_fonts.rs
emu_to_pt
called by 97
crates/office2pdf/src/parser/units.rs
get_attr_i64
called by 75
crates/office2pdf/src/parser/xml_util.rs
convert_bytes
called by 69
crates/office2pdf/src/lib.rs
get_attr_str
called by 68
crates/office2pdf/src/parser/xml_util.rs

Shape

Function 2,106
Method 186
Class 142
Enum 48
Interface 2

Languages

Rust100%

Modules by API surface

crates/office2pdf/src/parser/omml_tests.rs68 symbols
crates/office2pdf/tests/docx_fixtures.rs55 symbols
crates/office2pdf/src/parser/pptx_text.rs55 symbols
crates/office2pdf/src/render/typst_gen.rs52 symbols
crates/office2pdf/src/render/typst_gen_lists.rs45 symbols
crates/office2pdf/src/ir/elements.rs43 symbols
crates/office2pdf/src/render/pdf_tests.rs39 symbols
crates/office2pdf/src/render/typst_gen_text.rs38 symbols
crates/office2pdf/src/parser/pptx.rs38 symbols
crates/office2pdf/src/render/font_subst_tests.rs36 symbols
crates/office2pdf/src/parser/docx_foundation_tests.rs36 symbols
crates/office2pdf/src/parser/pptx_emf.rs34 symbols

For agents

$ claude mcp add office2pdf \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact