orthros / dart-epub Goto Github PK
View Code? Open in Web Editor NEWEpub Reader and Writer for Dart
License: MIT License
Epub Reader and Writer for Dart
License: MIT License
The following code will print true false
:
var reference = new EpubBook();
reference
..Author = "orthros"
..AuthorList = ["orthros"]
..Chapters = [new EpubChapter()]
..Content = new EpubContent()
..CoverImage = image.Image(100, 100)
..Schema = new EpubSchema()
..Title = "A Dissertation on Epubs";
EpubBook testBook;
testBook = new EpubBook();
testBook
..Author = "orthros"
..AuthorList = ["orthros"]
..Chapters = [new EpubChapter()]
..Content = new EpubContent()
..CoverImage = image.Image(100, 100)
..Schema = new EpubSchema()
..Title = "A Dissertation on Epubs";
print(reference == testBook);
print(reference.hashCode == testBook.hashCode);
This bug is present in numerous classes with List fields.
There's a dart package out there, epub_write, which is supposed to add writing functionality, making it possible to (painstakingly) create epub files directly from epub book "references"
My suggestion, and question, is to merge that functionality into this package?
navigation_reader.dart:
String tocFileEntryPath =
ZipPathUtils.combine(contentDirectoryPath, tocManifestItem.Href);
zip_path_utils.dart:
static String combine(String directory, String fileName) {
if (directory == null || directory == "") {
return fileName;
} else {
return directory + "/" + fileName;
}
}
}
If the tocManifestItem.Href is a ralative path such as "./toc.ncx",the method combine() will return wrong path like OEBPS/./toc.ncx,and error occurred.
Ralative path should be considered in method combine.
Thanks.
Do you have the plan writting an epub reader with highlights?thanks!
@orthros I'm trying to do exactly that, but I'm getting a decoding error. Can you point me in the right direction?
E/flutter (17553): [ERROR:flutter/lib/ui/painting/codec.cc(100)] Failed decoding image. Data is either invalid, or it is encoded using an unsupported format.
I/flutter (17553): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter (17553): The following _Exception was thrown resolving an image codec:
I/flutter (17553): Exception: operation failed
Doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.7.3, on Microsoft Windows [Version 10.0.17134.285], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[√] Android Studio (version 3.1)
[√] Connected devices (1 available)
• No issues found!
Hi,
I'm trying to play with this package but until now I get the following error when doing flutter packages get
:
Package epub has no versions that match >=1.2.0 <2.0.0 derived from:
- EpubTestApp depends on version ^1.2.0
Any idea? Thanks a lot in advance!
Hi all,
How to extract Epub Content with Epub plugin ^2.0.0,
This package requires an update with null safety support.
I have a larg epub which contain images and near 1000 pages
it takes 10 second to read , i think it should read couple of page at a time not to read the whole book.
Hi,
Please can you check this epub book ? Year Five Maths: Operations on Numbers
The part of the code:
_readEpubFile(String filePath) async {
var targetFile = new io.File(filePath);
List<int> bytes = await targetFile.readAsBytes();
EpubBook epubBook = await EpubReader.readBook(bytes);
EpubContent bookContent = epubBook.Content;
Map<String, EpubTextContentFile> htmlFiles = bookContent.Html;
StringBuffer sb = StringBuffer();
htmlFiles.values.forEach((EpubTextContentFile htmlFile) {
String htmlContent = htmlFile.Content;
sb.write(htmlContent);
});
It's throwing an exception:
E/flutter ( 7117): #15 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
E/flutter ( 7117): #16 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
E/flutter ( 7117): #17 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
E/flutter ( 7117): #18 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
E/flutter ( 7117): #19 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
E/flutter ( 7117): #20 _invoke1 (dart:ui/hooks.dart:142:13)
E/flutter ( 7117): #21 _dispatchPointerDataPacket (dart:ui/hooks.dart:99:5)
Thanks
This is probably an archive
fault, but best to start mentioning it here, as it also affects this package:
for (var file in files) {
if (verbose) print("Getting file " + file.path);
EpubBook book =
await EpubReader.readBook(new File.fromUri(file.uri).readAsBytesSync());
if (verbose) print(" " + book?.Title);
...
}
Resulting (after a while) into the following throw:
Getting file D:/Google Drive/Books\Complete Turnabout - Nenilein.epub
Unhandled exception:
Exception: EPUB parsing error: file OEBPS/Mentor-and-Protégé.html not found in archive.
#0 EpubContentFileRef.getContentFileEntry (package:epub/src/ref_entities/epub_content_file_ref.dart:47:7)
#1 EpubContentFileRef.getContentStream (package:epub/src/ref_entities/epub_content_file_ref.dart:34:30)
#2 EpubContentFileRef.readContentAsText (package:epub/src/ref_entities/epub_content_file_ref.dart:28:31)
<asynchronous suspension>
#3 EpubReader.readTextContentFiles.<anonymous closure> (package:epub/src/epub_reader.dart:100:45)
<asynchronous suspension>
#4 Future.forEach.<anonymous closure> (dart:async/future.dart:484)
#5 Future.doWhile.<anonymous closure> (dart:async/future.dart:526)
#6 _RootZone.runUnaryGuarded (dart:async/zone.dart:1316)
#7 _RootZone.bindUnaryCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1355)
#8 _RootZone.runUnary (dart:async/zone.dart:1381)
#9 _FutureListener.handleValue (dart:async/future_impl.dart:129)
#10 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:638)
#11 Future._propagateToListeners (dart:async/future_impl.dart:667)
#12 Future._complete (dart:async/future_impl.dart:472)
#13 _SyncCompleter.complete (dart:async/future_impl.dart:51)
#14 _completeOnAsyncReturn (dart:async-patch/dart:async/async_patch.dart:292)
#15 EpubReader.readTextContentFiles.<anonymous closure> (package:epub/src/epub_reader.dart:102:5)
#16 _RootZone.runUnary (dart:async/zone.dart:1381)
#17 _FutureListener.handleValue (dart:async/future_impl.dart:129)
#18 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:638)
#19 Future._propagateToListeners (dart:async/future_impl.dart:667)
#20 Future._complete (dart:async/future_impl.dart:472)
#21 _SyncCompleter.complete (dart:async/future_impl.dart:51)
#22 _completeOnAsyncReturn (dart:async-patch/dart:async/async_patch.dart:292)
#23 EpubContentFileRef.readContentAsText (package:epub/src/ref_entities/epub_content_file_ref.dart:30:5)
#24 new Future.microtask.<anonymous closure> (dart:async/future.dart:200)
#25 _microtaskLoop (dart:async/schedule_microtask.dart:41)
#26 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#27 _runPendingImmediateCallback (dart:isolate-patch/dart:isolate/isolate_patch.dart:113)
#28 _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:166)
Changing lib/src/ref_entities/epub_content_file_ref.dart:~40 to this:
ArchiveFile contentFileEntry = epubBookRef.EpubArchive().files.firstWhere(
(ArchiveFile x) {print(x.name);return x.name == contentFilePath;},
orElse: () => null);
Reveals that the archive files are named like this:
OEBPS/Miseries.html
OEBPS/First-Investigations.html
OEBPS/Mentor-and-Protégé.html
OEBPS/Mayas-Objection.html
OEBPS/Alone.html
Here is the epub file in question (zipped, as github doesnt accept .epub files)
Complete Turnabout - Nenilein.zip
It was downloaded from http://ficsave.xyz
Because xml2json >=4.2.1 depends on xml ^4.2.0 and epub 2.1.0 depends on xml >=2.6.0 <4.0.0, xml2json >=4.2.1 is incompatible with epub 2.1.0.
And because no versions of epub match >2.1.0 <3.0.0, xml2json >=4.2.1 is incompatible with epub ^2.1.0.
How to Add Page Number on top of the Books Contents ?
Could we support create epub from folder, we only description some meta data and toc nav, and the zip task will run on isolate.
Getting this when I do flutter packages get
The current Dart SDK version is 2.0.0-dev.63.0.flutter-4c9689c1d2.
Because e_reader depends on epub >=2.0.0 which requires SDK version >=2.0.0 <3.0.0, version solving failed.
Seems to be related/similar to the other issue in this project. I also noticed there was a recent commit that may be resolving this issue.
There doesn't seem to be an epub renderer out there. Is this something you've thought about or would like help doing?
I tried loading the cover image as per flutter app example, and the library seems to have trouble finding the cover image of the epub file even though it exists (confirmed via other apps and me looking at its meta data).
Here is the code :
Widget buildDocumentItem(epub.EpubBookRef book) {
return Card(
child: InkWell(
splashColor: Colors.black.withAlpha(30),
onTap: () {
},
child: Column(
children: <Widget>[
FutureBuilder<epub.Image>(
future: book.readCover(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Image.memory(image.encodeJpg(snapshot.data));
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
return Container();
}
),
Text(book.Title),
Text(book.Author),
]
),
),
);
}
Any idea?
I'm having this error when calling, file.readAsBytes() in an Epub3 file..
E/flutter (28533): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: FormatException: Unexpected extension byte (at offset 139)
Please update XML dependency
Always says not found for me.
In dart, the convention is camelCase, final fields, and now, nnbd. The package needs an great migration. I did it at my github, but it is an humongous breaking change and contains 3 packages that i made and didnt publish to pub.dev. I tried to only migrate to nnbd but because the fields are set after object initialization, it proved to be rather chalenging. So as it was becoming an big breaking change with big consequences i ended up doing it my way.
Hi, and thanks for sharing this dart package. Just a question, did you test it on files that have sizes > 2 mega bytes ?
I'm asking because if this is a memory friendly when the file size is big, maybe the app will crash.
Thanks
When a file path contains whitespaces, its href attribute in the manifest may be encoded:
<item id="x001-Title.xhtml" href="Text/001%20-%20Title.xhtml" media-type="application/xhtml+xml"/>
In this case its content cannot be opened.
Sorry if I'm posting in the wrong section I did try contacting Colin awhile back via email but heard nothing back, I've also asked on StackOverflow.
Are there any examples showing how to use this inside a flutter application? Any guidance would be greatly appreciated.
I was using epub package just to see how it works. I read an epub book with
EpubBook epubBook = await EpubReader.readBook(bytes);
then i saved it without any changes then I read it again
var written = EpubWriter.writeBook(epubBook); var newBook = await EpubReader.readBook(written);
I got "EPUB parsing error: root file not found in archive." exception.
I investigated for a while and I found:
I think the following quick patch of EpubWriter can help and, perhaps, it's possible to apply an even better one.
static Archive _createArchive(EpubBook book) {
var arch = Archive();
final StringBuffer buffer = StringBuffer('<?xml version="1.0"?><container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container"><rootfiles><rootfile full-path=')
..write('"')
..write(book.Schema.ContentDirectoryPath)
..write(book.Schema.ContentDirectoryPath.isEmpty ? 'content.opf' : '/content.opf' )
..write('"')
..write(' media-type="application/oebps-package+xml"/></rootfiles></container>');
final String _container_file = buffer.toString();
// Add simple metadata
arch.addFile(ArchiveFile.noCompress(
"metadata", 20, convert.utf8.encode("application/epub+zip")));
// Add Container file
arch.addFile(ArchiveFile("META-INF/container.xml", _container_file.length,
convert.utf8.encode(_container_file)));
...
It loads everything first into memory which takes a lot of time that way. this is a problem when the epub file gets larger
Another problem that it doesn't have pagination which is something necessary.
something else is that you can't load images with HTML.
how to load images within the pages? it gives HTML and images separately
With an older version of flutter 0.5.1 and epub 1.3.2 I could load an image in a the Image widget with EpubByteContentFileRef.readContent()
and Image.memory(...)
. But with the latest flutter dev version 0.5.8 and epub 2.0.2 there is an exception: type 'List<int>' is not a subtype of type 'Uint8List'
See error below:
Because every version of flutter_test from sdk depends on async 2.1.0 and epub >=1.3.0 depends on async >=1.8.0 <2.1.0, flutter_test from sdk is incompatible with epub >=1.3.0.
I parse my epub book, encounter the below error tips
Exception: Incorrect EPUB manifest: item with href = "Qian%20Yan%20.html" is missing.
I found that inside bookRef.Content.Html
existing a similar key is 'Qian Yan .html', but here the contentFileName
was being urlencoded;
Add contentFileName = Uri.decodeFull(contentFileName);
to chapter_reader.dart:31 is working for me.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.