epub 2.0.7

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);

Changelog #

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

Unreleased #

[2.0.7] - 2019-05-22

Added #

  • Added example of using epub in a web page: examples/web_ex

Fixed #

  • Fixed errors from pedantic analysis

Changed #

  • Added pedantic analysis options

[2.0.6] - 2019-05-22

Fixed #

  • Fixed Issue #35: File cannot be opened if its path is url-encoded in the manifest
  • Updated examples/dart_ex to have a README as well as use a locally stored file.

[2.0.5] - 2019-05-16

Changed #

  • Exposed EpubChapterRef to consumers.

[2.0.4] - 2019-05-15

Fixed #

  • Merged pull request #45
    • Fixes pana hits to make code more readable

[2.0.3] - 2019-05-15

Changed #

  • Raised sdk version constraint to 2.0.0
  • Raised constraint on async to 3.0.0

Fixed #

  • Merged pull request #40 by vblago.
    • Fixes Undefined class 'XmlBuilder'

[2.0.2] - 2018-08-07

Changed #

  • Lowered sdk version constraint to 2.0.0-dev.61.0

[2.0.1] - 2018-08-07

Changed #

  • Formatted documents

[2.0.0] - 2018-08-07

Added #

  • Added support for writing Epubs back to Byte Arrays
  • Tests for writing Epubs

Changed #

  • Epub Readers and Writers now have their == operator and hashCode get-er overridden

Fixed #

  • Fixed an issue when reading EpubContentFileRef

[1.3.2] - 2018-08-01

Changed #

  • Updates to Travis configuration and publishing

[1.3.1] - 2018-08-01

Changed #

  • Updates to Travis configuration and publishing

Removed #

  • Removed unused variable FilePath from EpubBook and EpubBookRef

[1.3.0] - 2018-08-01

Added #

  • Package now supports Dart 2!

Removed #

  • Removed support for Dart 1.2.21

[1.2.10] - 2018-07-29

Fixed #

  • Merged pull request #15 from ShadowJonathan/dev.
    • Fixes issue with parsing schema by removing opf: namespace

[1.2.9] - 2018-03-13

Changed #

  • Ran code through dartfmt as per analysis by pana

[1.2.8] - 2018-03-13

Added #

  • Added unit tests for Images

Changed #

  • Updated dependencies

[1.2.7] - 2018-03-13

Added #

  • Added upper limit of Dart version to 2.0.1

[1.2.6] - 2018-03-12

Added #

  • Added Support for Dart 2.0

[1.2.5] - 2018-02-20

Added #

  • A publish step in the travis deploy

[1.2.4] - 2018-01-26

Changed #

  • EnumFromString no longer uses the mirrors package to make this Flutter compatible by @MostafaAyesh

[1.2.3] - 2018-01-26

Added #

  • This Changelog!

Changed #

  • Author email

[1.2.2] - 2017-01-26

Changed #

  • Dependencies were updated to more permissive versions by @jarontai

Added #

  • Example by @jarontai
  • More Entities and types are exported by @jarontai

Fixed #

  • Issue with case sensitivity in switch statements from @jarontai
  • Issue with Async Loops from @jarontai

[1.2.1] - 2017-05-28

Fixed #

  • Made code in line with Dart styleguide

example/README.md

Examples #

dart_ex #

This example reads an EPUB from disk and logs various information about it.

flutter_ex #

This example fetches an EPUB from a user-inputted URL and displays the Title and Author.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  epub: ^2.0.7

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:epub/epub.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
75
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
87
Learn more about scoring.

We analyzed this package on Jul 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:epub/epub.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
archive ^2.0.0 2.0.10
async >=1.8.0 <3.0.0 2.3.0
dart2_constant ^1.0.1 1.0.2+dart2
image >=1.1.33 <3.0.0 2.1.4
quiver >=2.0.0 <3.0.0 2.0.3
xml >=2.6.0 <4.0.0 3.5.0
Transitive dependencies
args 1.5.2
charcode 1.1.2
collection 1.14.11
convert 2.1.1
crypto 2.0.6
matcher 0.12.5
meta 1.1.7
petitparser 2.4.0
stack_trace 1.9.3
typed_data 1.1.6
Dev dependencies
path ^1.5.1 1.6.2
test ^1.0.0

Admin