epub 2.0.2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 86

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.2] - 2018-08-07

Changed

  • Lowered sdk version constraint to 2.0.0-dev.61.0

[2.0.1] - 2018-08-07

Chaned

  • 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/example.dart

import 'dart:io' as io;

import 'package:path/path.dart' as path;
import 'package:epub/epub.dart';

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

// Opens a book and reads all of its content into the 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.isNotEmpty ? images.values.first : null;

// 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((contributor) {
    String contributorName = contributor.Contributor;
    String contributorRole = contributor.Role;
  });

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

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

  // Write the Book
  var written = EpubWriter.writeBook(epubBook);
  // Read the book into a new object!
  var newBook = await EpubReader.readBook(written);
}

Use this package as a library

1. Depend on it

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


dependencies:
  epub: ^2.0.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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';
  
Version Uploaded Documentation Archive
2.0.2 Aug 8, 2018 Go to the documentation of epub 2.0.2 Download epub 2.0.2 archive
2.0.1 Aug 8, 2018 Go to the documentation of epub 2.0.1 Download epub 2.0.1 archive
2.0.0 Aug 8, 2018 Go to the documentation of epub 2.0.0 Download epub 2.0.0 archive
1.3.2 Aug 2, 2018 Go to the documentation of epub 1.3.2 Download epub 1.3.2 archive
1.3.1 Aug 2, 2018 Go to the documentation of epub 1.3.1 Download epub 1.3.1 archive
1.3.0 Aug 2, 2018 Go to the documentation of epub 1.3.0 Download epub 1.3.0 archive
1.2.10 Jul 30, 2018 Go to the documentation of epub 1.2.10 Download epub 1.2.10 archive
1.2.9 Mar 19, 2018 Go to the documentation of epub 1.2.9 Download epub 1.2.9 archive
1.2.8 Mar 13, 2018 Go to the documentation of epub 1.2.8 Download epub 1.2.8 archive
1.2.7 Mar 13, 2018 Go to the documentation of epub 1.2.7 Download epub 1.2.7 archive

All 21 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
72
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]
86
Learn more about scoring.

We analyzed this package on Aug 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.11.8

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-dev.61.0 <3.0.0
archive ^2.0.0 2.0.2
async >=1.8.0 <2.1.0 2.0.8
dart2_constant ^1.0.1 1.0.2+dart2
image >=1.1.33 <3.0.0 2.0.4
quiver >=2.0.0 <3.0.0 2.0.0+1
xml >=2.6.0 <4.0.0 3.2.0
Transitive dependencies
args 1.5.0
charcode 1.1.2
collection 1.14.11
convert 2.0.2
crypto 2.0.6
matcher 0.12.4
meta 1.1.6
petitparser 2.0.0
stack_trace 1.9.3
typed_data 1.1.6
Dev dependencies
path ^1.5.1 1.6.2
test ^1.0.0