iepub
EPUB
支持从文件和内存读取和生成EPUB电子书
生成
- 可以使用
EpubBook
结构体手动生成epub - (推荐)使用
EpubBuilder
快速生成
use EpubHtml;
use EpubBuilder;
default
.with_title
.with_creator
.with_date
.with_description
.with_identifier
.with_publisher
.add_chapter
.add_assets
.metadata
.metadata
.file
.unwrap;
读取
use ;
let mut data = Vec new;// epub的二进制数据
let mut book = read_from_vec;
// 从文件读取
let mut bbook = read_from_file;
注意事项
iepub
使用EpubHtml
来存储章节内容,但是EpubHtml#data
实际只会存储 html>body 节点内的内容,并且不包括body节点的属性(attribute),其他比如样式表将会存放在其他属性中- 不同的阅读器对于文件名的兼容性不同,这里建议文件最好使用
.xhtml
后缀,例如EpubHtml::default().with_file_name("1.xhtml")
自定义目录
- 如果需要自定义目录,需要调用
custome_nav(true)
,然后调用add_nav()
添加目录
自动生成封面
自动生成黑底白字,写着书籍名的封面图
需要启用feature cover
,然后调用auto_gen_cover(true)
,同时需要调用with_font(font)
设置字体文件位置。
mobi
读取
use *;
let path = current_dir.unwrap.join;
let mut mobi = new.unwrap;
let book = mobi.load.unwrap;
写入
使用builder
let v = default
.with_title
.with_creator
.with_date
.with_description
.with_identifier
.with_publisher
.append_title
.custome_nav
.add_chapter
// .file("builder.mobi")
.mem
.unwrap;
自定义目录
- 如果需要自定义目录,需要调用
custome_nav(true)
,然后调用add_nav()
添加目录 - 为了关联目录nav和章节chap,需要调用
MobiNav#set_chap_id()
指明指向的章节;如果是类似卷首目录,指向最接近的章节即可
图片
- mobi格式中图片是不存在文件路径的,如果需要添加图片,首先在章节中使用
img
标签的src属性,随便给个文件名,只要不重复就行,然后添加图片的时候也指向同一个文件名,最后写入就会添加图片了 - 由于mobi设计原因,如果某个图片未被引用,最终仍然会被写入到文件,但是不可索引,不可查看,只能白白占用空间
- 另外封面需要调用
cover()
设置
标题
默认情况下会在章节的html片段前面加一段标题xml,如果章节内容里本身就有可阅读的标题,设置append_title(false)
自动生成封面
自动生成黑底白字,写着书籍名的封面图
需要启用feature cover
,然后调用auto_gen_cover(true)
,同时需要调用with_font(font)
设置字体文件位置。
转换
mobi -> epub
use *;
let mut book = open
.map_err
.and_then
.and_then
.unwrap;
let mut epub = mobi_to_epub.unwrap;
epub.write.unwrap;
epub -> mobi
use *;
let mut epub = default;
let mobi = epub_to_mobi.unwrap;
let mut v = new;
new
.unwrap
.with_append_title
.write
.unwrap;
命令行工具
tool目录为命令行工具,支持mobi和epub格式,但是不同格式支持的命令不尽相同
目前支持
- 获取元数据,如标题、作者
- 修改元数据
- 提取封面
- 提取所有图片
- 提取某章节文本
- 获取目录
- 格式转换
可通过-h
获取使用方法说明