The engine is a Rust library on crates.io. A program opens a
file once and then takes its pages for its own drawing code, as
images or as a PDF file.
cargo add f-office
use f_office::{Document, FontDatabase, Options};
let mut fonts = FontDatabase::new();
fonts.add_files(&["fonts/TinosCF-Regular.ttf".into()])?;
let docx = std::fs::read("report.docx")?;
let document = Document::open(&docx, &fonts, &Options::default())?.value;
for page in document.pages() {
println!("{:?} by {:?}", page.width(), page.height());
}
std::fs::write("report.pdf", document.write_pdf(&fonts)?.value)?;
The same Rust code builds for your computer and as WebAssembly
for a web page, so a page can draw documents in the browser with
no server. The headless engine (@f-office/core) and
drop-in F-Office Docs component (@f-office/docs)
are on npm, with
compatifont's open fonts (@compatifont/fonts).
npm install @f-office/core @f-office/docs @compatifont/fonts
The F stands for Free. F-Office is free and open source, so you
can use it at work or at home with no fee to pay and no EULA to
accept. The engine with its command line tool and the open fonts
are on GitHub.
F-Office is early work, and its API can still change at any
time. It renders Word documents today, and the other Office
files will follow.