搜索插件、代码仓与 APP 分类

插件详情v2.1.0

epub

Dart 的 Epub 解析器。适用于服务器、Web 或 Flutter 中使用

近 30 天下载
352
喜欢数
54
Pub 分数
35

安装插件

flutter pub add epub

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

epub 包是一个 Dart 库,用于解析和读取 EPUB 文件,设计用于在服务器、Web 和 Flutter 环境中运行。它使开发者能够以编程方式提取 EPUB 文档的内容、元数据和结构。该包支持标准 EPUB 格式,并提供对章节、图像和样式信息的访问。适用于需要电子书处理的应用程序,如阅读器、转换器或内容管理系统。

适合场景

  • 在Flutter应用中读取EPUB文件
  • 在服务器上解析电子书
  • 将EPUB内容转换为其他格式
  • 构建电子阅读器应用程序
  • 从电子书提取元数据

主要特点

  • 支持标准 EPUB 格式
  • 跨平台兼容性
  • 提取章节、图片和元数据
  • 轻量且高效
  • 开源且持续维护

适合对象

  • 需要电子书支持的Flutter移动应用
  • 服务器端电子书处理
  • 基于网络的电子阅读器工具
  • 内容聚合平台
  • 教育或出版软件

使用建议

  • 仅限EPUB解析(不支持写入)
  • 需要有效的 EPUB 文件
  • 无内置渲染引擎
  • 依赖外部依赖项进行显示
  • 未针对非常大的 EPUB 文件进行优化

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

dart-epub

Build Status

Epub Reader and Writer for Dart inspired by this fantastic C# Epub Reader

This does not rely on the dart:io package in any way, so it is avilable for both desktop and web-based implementations

Installing

Add the package to the dependencies section of your pubspec.yaml

dependencies:
  epub: ^2.0.0

Example


//Get the epub into memory somehow
String fileName = "hittelOnGoldMines.epub";
String fullPath = path.join(io.Directory.current.path, fileName);
var targetFile = new io.File(fullPath);
List<int> bytes = await targetFile.readAsBytes();


// Opens a book and reads all of its content into memory
EpubBook epubBook = await EpubReader.readBook(bytes);
            
// COMMON PROPERTIES

// Book's title
String title = epubBook.Title;

// Book's authors (comma separated list)
String author = epubBook.Author;

// Book's authors (list of authors names)
List<String> authors = epubBook.AuthorList;

// Book's cover image (null if there is no cover)
Image coverImage = epubBook.CoverImage;

            
// CHAPTERS

// Enumerating chapters
epubBook.Chapters.forEach((EpubChapter chapter) {
  // Title of chapter
  String chapterTitle = chapter.Title;
              
  // HTML content of current chapter
  String chapterHtmlContent = chapter.HtmlContent;

  // Nested chapters
  List<EpubChapter> subChapters = chapter.SubChapters;
});

            
// CONTENT

// Book's content (HTML files, stlylesheets, images, fonts, etc.)
EpubContent bookContent = epubBook.Content;

            
// IMAGES

// All images in the book (file name is the key)
Map<String, EpubByteContentFile> images = bookContent.Images;

EpubByteContentFile firstImage = images.values.first;

// Content type (e.g. EpubContentType.IMAGE_JPEG, EpubContentType.IMAGE_PNG)
EpubContentType contentType = firstImage.ContentType;

// MIME type (e.g. "image/jpeg", "image/png")
String mimeContentType = firstImage.ContentMimeType;

// HTML & CSS

// All XHTML files in the book (file name is the key)
Map<String, EpubTextContentFile> htmlFiles = bookContent.Html;

// All CSS files in the book (file name is the key)
Map<String, EpubTextContentFile> cssFiles = bookContent.Css;

// Entire HTML content of the book
htmlFiles.values.forEach((EpubTextContentFile htmlFile) {
  String htmlContent = htmlFile.Content;
});

// All CSS content in the book
cssFiles.values.forEach((EpubTextContentFile cssFile){
  String cssContent = cssFile.Content;
});


// OTHER CONTENT

// All fonts in the book (file name is the key)
Map<String, EpubByteContentFile> fonts = bookContent.Fonts;

// All files in the book (including HTML, CSS, images, fonts, and other types of files)
Map<String, EpubContentFile> allFiles = bookContent.AllFiles;


// ACCESSING RAW SCHEMA INFORMATION

// EPUB OPF data
EpubPackage package = epubBook.Schema.Package;

// Enumerating book's contributors
package.Metadata.Contributors.forEach((EpubMetadataContributor contributor){
  String contributorName = contributor.Contributor;
  String contributorRole = contributor.Role;
});

// EPUB NCX data
EpubNavigation navigation = epubBook.Schema.Navigation;

// Enumerating NCX metadata
navigation.Head.Metadata.forEach((EpubNavigationHeadMeta meta){
  String metadataItemName = meta.Name;
  String metadataItemContent = meta.Content;
});

// Writing Data
var written = await EpubWriter.writeBook(epubBook);

// You can even re-read the book into a new object! 
var bookRoundTrip = await EpubReader.readBook(written);

所属分类

依赖

依赖清单 6 项

源码仓库

使用此插件的项目

暂无相关数据。