Skip to main content

Crate office2pdf

Crate office2pdf 

Source
Expand description

Pure-Rust conversion of Office documents (DOCX, PPTX, XLSX) to PDF.

§Quick start (native only)

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

§With options (native only)

use office2pdf::config::{ConvertOptions, PaperSize, SlideRange};

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

§In-memory conversion (works on all targets including WASM)

use office2pdf::config::{ConvertOptions, 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();

Modules§

config
error
ir
parser
render

Functions§

convert
Convert a file at the given path to PDF bytes with warnings.
convert_bytes
Convert raw bytes of a known format to PDF bytes with warnings.
convert_with_options
Convert a file at the given path to PDF bytes with options.
render_document
Render an IR Document to PDF bytes.