epub 1.2.9

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

dart-epub

Build Status

Epub Reader 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: ^1.2.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 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.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;
});

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]

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

1. Depend on it

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


dependencies:
  epub: "^1.2.9"

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 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
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
1.2.6 Mar 13, 2018 Go to the documentation of epub 1.2.6 Download epub 1.2.6 archive
1.2.5 Mar 12, 2018 Go to the documentation of epub 1.2.5 Download epub 1.2.5 archive
1.2.4 Jan 26, 2018 Go to the documentation of epub 1.2.4 Download epub 1.2.4 archive
1.2.3 Jan 26, 2018 Go to the documentation of epub 1.2.3 Download epub 1.2.3 archive
1.2.2 Jan 26, 2018 Go to the documentation of epub 1.2.2 Download epub 1.2.2 archive
1.2.1 May 28, 2017 Go to the documentation of epub 1.2.1 Download epub 1.2.1 archive
1.2.0 May 28, 2017 Go to the documentation of epub 1.2.0 Download epub 1.2.0 archive

All 14 versions...

Analysis

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

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

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

Platforms

Detected platforms: Flutter, web, other

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

Suggestions

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 4 hints.

    Strong-mode analysis of lib/src/readers/navigation_reader.dart gave the following hint:

    line: 55 col: 19
    'UTF8' is deprecated and shouldn't be used.

    Strong-mode analysis of lib/src/readers/package_reader.dart gave the following hint:

    line: 32 col: 19
    'UTF8' is deprecated and shouldn't be used.

    Similar analysis of the following files failed:

    • lib/src/readers/root_file_path_reader.dart (hint)
    • lib/src/ref_entities/epub_content_file_ref.dart (hint)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.21.0 <2.0.1
archive ^1.0.33 1.0.33
async >=1.8.0 <2.1.0 2.0.6
image ^1.1.30 1.1.31
xml >=2.6.0 <4.0.0 3.0.0
Transitive dependencies
args 1.4.2
browser 0.10.0+3
charcode 1.1.1
collection 1.14.9
convert 2.0.1
crypto 2.0.2+1
matcher 0.12.2
petitparser 1.7.6
stack_trace 1.9.2
typed_data 1.1.5
Dev dependencies
path ^1.5.1 1.5.1
test ^0.12.0