epub 1.2.4

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

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.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.4"

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.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
1.1.2 May 14, 2017 Go to the documentation of epub 1.1.2 Download epub 1.1.2 archive
1.1.1 May 14, 2017 Go to the documentation of epub 1.1.1 Download epub 1.1.1 archive
1.1.0 May 12, 2017 Go to the documentation of epub 1.1.0 Download epub 1.1.0 archive
1.0.0 May 11, 2017 Go to the documentation of epub 1.0.0 Download epub 1.0.0 archive

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
40 / 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]
70

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 >=1.21.0 <2.0.0
archive ^1.0.33 1.0.33
async ^1.8.0 1.13.3 2.0.3
image ^1.1.29 1.1.29
xml ^2.6.0 2.6.0 3.0.0-alpha
Transitive dependencies
args 1.3.0
browser 0.10.0+2
charcode 1.1.1
collection 1.14.5
convert 2.0.1
crypto 2.0.2+1
matcher 0.12.1+4
petitparser 1.7.0
stack_trace 1.9.1
typed_data 1.1.5
Dev dependencies
path ^1.5.1 1.5.1
scheduled_test ^0.12.0
test ^0.12.0