| Crates.io | liber |
| lib.rs | liber |
| version | 0.1.0 |
| created_at | 2025-10-26 15:22:04.464134+00 |
| updated_at | 2025-10-26 15:22:04.464134+00 |
| description | Rust library for creating (sync/async) EPUB files |
| homepage | https://github.com/javiorfo/liber#readme |
| repository | https://github.com/javiorfo/liber |
| max_upload_size | |
| id | 1901534 |
| size | 148,373 |
Rust library for creating (sync/async) EPUB files
This crate provides a high-level, ergonomic API for creating EPUB files (2.0.1). It offers both asynchronous and blocking (synchronous) implementations, with flexible builders and output options.
Add this crate to your Cargo.toml:
[dependencies]
liber = "0.1.0"
[dependencies]
liber = { version = "0.1.0", features = ["async"] }
use liber::epub::{
ContentBuilder, ContentReference, EpubBuilder, ImageType, MetadataBuilder, ReferenceType,
Resource,
};
use std::path::Path;
fn main() {
match create() {
Err(e) => eprintln!("{e}"),
Ok(_) => println!("ok"),
}
}
fn create() -> Result<(), Box<dyn std::error::Error>> {
let mut file = std::fs::File::create("book.epub")?;
let title = "My Book";
let contents = vec![
ContentBuilder::new(
r#"<body><h1>Chapter 2</h1></body>"#.as_bytes(),
ReferenceType::Text("Chapter 2".to_string()),
)
.build(),
ContentBuilder::new(
r#"<body><h1>Chapter 3</h1></body>"#.as_bytes(),
ReferenceType::Text("Chapter 3".to_string()),
)
.add_child(
ContentBuilder::new(
r#"<body><h1>Chapter 4</h1></body>"#.as_bytes(),
ReferenceType::TitlePage("Chapter 4".to_string()),
)
.build(),
)
.build(),
];
let epub_builder = EpubBuilder::new(MetadataBuilder::title(title).creator("author").build())
.stylesheet("body {}".as_bytes())
.cover_image(Path::new("/path/to/img.jpg"), ImageType::Jpg)
.add_resource(Resource::Font(Path::new("/path/to/some_font.otf")))
.add_content(
ContentBuilder::new(
r#"<body><h1>Chapter 1</h1><h2 id="id01">Section 1.1</h2><h2 id="id02">Section 1.1.1</h2><h2 id="id03">Section 1.2</h2></body>"#.as_bytes(),
ReferenceType::Text("Chapter 1".to_string()),
)
.add_content_reference(ContentReference::new("Section 1.1").add_child(ContentReference::new("Section 1.1.1")))
.add_content_reference(ContentReference::new("Section 1.2"))
.add_children(contents)
.build(),
);
epub_builder.create(&mut file)?;
Ok(())
}
Find all the configuration options in the full documentation.