EMF SDK for Rust
emfsdk is a pure-Rust library for reading, editing, and writing EMF, EMF+,
and WMF metafiles. Known records are typed; unknown records, extensions,
padding, strings, and opaque payloads retain the bytes needed for round trips.
Usage
use ;
use Metafile;
Use EmfMetafile, WmfMetafile, and record parse_data methods for typed
format-specific access. rebuild_typed reconstructs a record through its typed
writer while preserving its wire metadata.
For read-only work, MetafileRef, EmfMetafileRef, WmfMetafileRef, and
EmfPlusStreamRef validate framing and borrow record payloads from the input.
Their iterators allocate nothing. Call into_owned before editing or writing.
Top-level write_to methods accept any std::io::Write; output does not need
to implement Seek. Use to_bytes only when an in-memory file image is
required.
Compatibility
Metafile::from_bytes is compatibility-first. Producer-specific reserved
values and bounded extensions are preserved and reported by
compatibility_diagnostics.
Use Metafile::from_bytes_strict or validate_strict when every known field
must conform to the Microsoft specifications. Unknown record types remain an
explicit raw fallback; malformed known records are not silently accepted as
typed data.
Features
- Default: parsing and writing only
render: raster rendering withimage,fontdb, andttf-parser
The minimum supported Rust version is 1.88. The crate uses Rust 2024.
Specifications and testing
Corpus tests in
ooxmlsdk-test-suite
exercise typed parse/write and exact whole-file comparison against standalone
and Office-embedded metafiles. Compatibility fallbacks and failures are
counted, not skipped.
Status
The crate is pre-1.0 and its API may still change. The optional renderer targets portable previews, not pixel-identical Windows GDI/GDI+ output.
See CHANGELOG.md for release notes.
License
MIT OR Apache-2.0