ofd-rs
Rust library for creating OFD (Open Fixed-layout Document) files, based on the Chinese national standard GB/T 33190-2016.
What is OFD?
OFD (Open Fixed-layout Document) is a fixed-layout document format standardized by the Chinese national standard GB/T 33190-2016. It serves a similar role to PDF and is widely used in Chinese government and enterprise document workflows, especially for electronic invoices, official documents, and archival purposes.
An OFD file is a ZIP archive containing XML descriptors and embedded resources (images, fonts, etc.).
Installation
Add to your Cargo.toml:
[]
= "0.1"
Quick Start
use ;
// Convert a JPEG image to a single-page OFD document
let jpeg_bytes = read.unwrap;
let ofd = from_images.build.unwrap;
write.unwrap;
Features
Current (v0.1)
- Image to OFD - Convert images (JPEG, PNG, BMP, TIFF) to OFD documents
- Multi-page support - Combine multiple images into a single OFD file
- Mixed page sizes - Each page can have different dimensions
- Custom metadata - Set document title, author, creator, creation date
- Builder pattern - Flexible API for constructing OFD documents
- Spec compliant - Follows GB/T 33190-2016 namespace and structure conventions
- Minimal dependencies - Only
zipanduuid, no heavy XML frameworks
API Overview
Quick API - One image per page:
use ;
let ofd = from_images.build?;
Builder API - More control:
use ;
let mut writer = new;
writer.set_doc_info;
writer.add_image_page; // A4 size in mm
let ofd = writer.build?;
Page size options:
// From pixel dimensions + DPI (auto-calculates mm)
jpeg;
// From explicit mm dimensions
jpeg_mm;
// Any format with explicit mm dimensions
new;
OFD File Structure
The generated OFD follows this structure:
output.ofd (ZIP)
├── OFD.xml # Entry point
└── Doc_0/
├── Document.xml # Document root (pages, resources)
├── DocumentRes.xml # Image resource declarations
├── PublicRes.xml # Fonts, color spaces
├── Pages/
│ ├── Page_0/Content.xml # Page 0 content
│ ├── Page_1/Content.xml # Page 1 content
│ └── ...
└── Res/
├── Image_0.jpg # Embedded image files
├── Image_1.jpg
└── ...
Roadmap
- OFD Reader - Parse and extract content from existing OFD files
- Text rendering - TextObject support with font embedding
- Vector graphics - PathObject for lines, curves, shapes
- Digital signatures - Electronic seal and signature support (GB/T 38540)
- Template rendering - Generate OFD from templates with dynamic data
- PDF to OFD - Convert PDF documents to OFD format
- OFD to PDF - Convert OFD documents to PDF format
License
Licensed under Apache License 2.0. See LICENSE for details.