mertakdut / epubparser Goto Github PK
View Code? Open in Web Editor NEWParses .epub files, provides seperation page by page.
License: Apache License 2.0
Parses .epub files, provides seperation page by page.
License: Apache License 2.0
It becomes more and more sluggish as one moves along a book and on very large books it will crash because of that I think your proble lies in this code in the Content class, below:
BookSection maintainBookSections(int index) throws ReadingException, OutOfPagesException {
if (peakPage == index) { // Moving in order.
peakPage++;
} else {
while (peakPage < index) { // Trying to move forward. Calculate the ones before first.
getBookSection(peakPage++);
}
}
return getBookSection(index);
}
Do you have a sample using this library?
Epub file with single page in each chapter gets render properly but when number of pages in each chapter increases order gets change(i.e on click of chapter-2 it displays content of another chapter).
Hello,
Is there any way to find out number of sections.?
so that i can go for viewpager and it will make my task easy.
thank you.
How I can get images from epub? Not cover image but all images.
Is there an easy way to skip to a specific page?
I have tried:
int customPageNumber = 25;
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setCurrentItem(customPageNumber);
but I get a strange bug where the next few pages are repeats. My goal is to create a bookmark effect by manually inserting the desired page number.
Tested on the sample application.
Also:
mViewPager.setOffscreenPageLimit(0);
outputs this message:
W/ViewPager: Requested offscreen page limit 0 too small; defaulting to 1
can you provide a sample with font change and TOC ? and theme change?
It would be better if you could join the menu.
The links in the epub files are not opening. Always shows that page not available on below android version 19 KitKat and the blank page in above android version 19.
opf:guide did not load, when the node name is "opf:guide",
I think you change equals to endwiths method
`
boolean fillContent(Node node) throws ReadingException {
if(node.getNodeName().equals("metadata")) {
this.getMetadata().fillAttributes(node.getChildNodes());
this.isMetadataFound = true;
} else if(node.getNodeName().equals("manifest")) {
this.getManifest().fillXmlItemList(node.getChildNodes());
this.isManifestFound = true;
} else if(node.getNodeName().equals("spine")) {
this.getSpine().fillXmlItemList(node.getChildNodes());
this.isSpineFound = true;
} else if(node.getNodeName().equals("guide")) {
this.getGuide().fillXmlItemList(node.getChildNodes());
this.isGuideFound = true;
}
return this.isMetadataFound && this.isManifestFound && this.isSpineFound && this.isGuideFound;
}
<opf:package xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcms="http://www.dcms.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" unique-identifier="bookid" version="3.0">
opf:metadata
<dc:creator opf:role="aut" opf:file-as="Sussman, Jeffrey">Jeffrey Sussman</dc:creator>
dc:titleMax Baer and Barney Ross</dc:title>
dc:descriptionIn the 1920s and 30s, anti-Semitism was rife in the United States and Europe. Jews needed symbols of strength and demonstrations of courage against their enemies, and they found both in two champions of boxing: Max Baer and Barney Ross. Baer was the only Jewish heavyweight champion in the twentieth century, while Ross was considered one of the greatest welterweight and lightweight champions of the era. Although their careers never crossed paths, their boxing triumphs played a common role in lifting the spirits of persecuted Jews.<br />In Max Baer and Barney Ross: Jewish Heroes of Boxing, Jeffrey Sussman chronicles the lives of two men whose successful bouts inside the ring served as inspiration for Jewish fans across the country and around the world. Though they came from very different backgrounds—Baer grew up on his family's ranch in California, while Ross roamed the tough streets of Chicago and was a runner for Al Capone—both would bask in the limelight as boxing...</dc:description>
dc:publisherRowman & Littlefield Publishers</dc:publisher>
dc:date2012-04-18T23:00:00+00:00</dc:date>
<opf:meta property="dcterms:modified">
2012-04-12T12:00:00Z
</opf:meta>
<dc:identifier id="bookid">
urn:isbn:undefined</dc:identifier>
dc:rightsundefined</dc:rights>
dc:coverageundefined</dc:coverage>
<opf:meta name="cover" content="cover-image"/>
<dc:subject xmlns="http://www.idpf.org/2007/opf">undefined</dc:subject>
<dc:contributor xmlns="http://www.idpf.org/2007/opf" opf:role="bkp">calibre (2.50.0) [http://calibre-ebook.com]</dc:contributor>
<dc:language xmlns="http://www.idpf.org/2007/opf">en-US</dc:language>
<dc:identifier xmlns="http://www.idpf.org/2007/opf" opf:scheme="calibre">b2fc722a-91da-47fe-a8dc-f52748dcc098</dc:identifier>
</opf:metadata>
opf:manifest
<opf:item href="toc.ncx" id="ncx" media-type="application/x-dtbncx+xml"/>
<opf:item href="toc_nav.xhtml" id="nav" media-type="application/xhtml+xml" properties="nav"/>
<opf:item href="1-A01-Rowman_frontmatter.xhtml" id="frontmatter" media-type="application/xhtml+xml"/>
<opf:item href="1-A01-Rowman_cover.xhtml" id="cover" media-type="application/xhtml+xml"/>
<opf:item href="css/xml2epub.css" id="css-file" media-type="text/css"/>
<opf:item href="3-B02-acknowledgments.xhtml" id="d44e9" media-type="application/xhtml+xml"/>
<opf:item href="4-B03-introduction.xhtml" id="d44e11" media-type="application/xhtml+xml"/>
<opf:item href="5-C01-chap01.xhtml" id="d44e13" media-type="application/xhtml+xml"/>
<opf:item href="6-C02-chap02.xhtml" id="d44e16" media-type="application/xhtml+xml"/>
<opf:item href="7-C03-chap03.xhtml" id="d44e18" media-type="application/xhtml+xml"/>
<opf:item href="8-C04-chap04.xhtml" id="d44e20" media-type="application/xhtml+xml"/>
<opf:item href="9-C05-chap05.xhtml" id="d44e22" media-type="application/xhtml+xml"/>
<opf:item href="10-C06-chap06.xhtml" id="d44e24" media-type="application/xhtml+xml"/>
<opf:item href="11-C07-chap07.xhtml" id="d44e26" media-type="application/xhtml+xml"/>
<opf:item href="12-C08-chap08.xhtml" id="d44e29" media-type="application/xhtml+xml"/>
<opf:item href="13-C09-chap09.xhtml" id="d44e31" media-type="application/xhtml+xml"/>
<opf:item href="14-C10-chap10.xhtml" id="d44e33" media-type="application/xhtml+xml"/>
<opf:item href="15-D01-appendixA.xhtml" id="d44e35" media-type="application/xhtml+xml"/>
<opf:item href="16-D02-appendixB.xhtml" id="d44e37" media-type="application/xhtml+xml"/>
<opf:item href="17-D03-bibliography.xhtml" id="d44e39" media-type="application/xhtml+xml"/>
<opf:item href="18-I01-index.xhtml" id="d44e42" media-type="application/xhtml+xml"/>
<opf:item href="19-J01-author.xhtml" id="d44e43" media-type="application/xhtml+xml"/>
<opf:item href="images/27-F06.tif.jpg" id="d64e3" media-type="image/jpeg"/>
<opf:item href="images/25-F04.tif.jpg" id="d64e5" media-type="image/jpeg"/>
<opf:item href="images/28-F07.tif.jpg" id="d64e7" media-type="image/jpeg"/>
<opf:item href="images/20-W01-cover.jpg" id="cover-image" media-type="image/jpeg"/>
<opf:item href="images/23-F02.tif.jpg" id="d64e11" media-type="image/jpeg"/>
<opf:item href="images/26-F05.tif.jpg" id="d64e14" media-type="image/jpeg"/>
<opf:item href="images/31-F10.tif.jpg" id="d64e16" media-type="image/jpeg"/>
<opf:item href="images/24-F03.tif.jpg" id="d64e18" media-type="image/jpeg"/>
<opf:item href="images/21-logo_tm.tif.png" id="d64e20" media-type="image/png"/>
<opf:item href="images/30-F09.tif.jpg" id="d64e22" media-type="image/jpeg"/>
<opf:item href="images/29-F08.tif.jpg" id="d64e24" media-type="image/jpeg"/>
<opf:item href="images/22-F01.tif.jpg" id="d64e27" media-type="image/jpeg"/>
</opf:manifest>
<opf:spine toc="ncx">
<opf:itemref idref="cover"/>
<opf:itemref idref="frontmatter"/>
<opf:itemref idref="d44e9"/>
<opf:itemref idref="d44e11"/>
<opf:itemref idref="d44e13"/>
<opf:itemref idref="d44e16"/>
<opf:itemref idref="d44e18"/>
<opf:itemref idref="d44e20"/>
<opf:itemref idref="d44e22"/>
<opf:itemref idref="d44e24"/>
<opf:itemref idref="d44e26"/>
<opf:itemref idref="d44e29"/>
<opf:itemref idref="d44e31"/>
<opf:itemref idref="d44e33"/>
<opf:itemref idref="d44e35"/>
<opf:itemref idref="d44e37"/>
<opf:itemref idref="d44e39"/>
<opf:itemref idref="d44e42"/>
<opf:itemref idref="d44e43"/>
</opf:spine>
opf:guide
<opf:reference href="1-A01-Rowman_cover.xhtml" title="Cover" type="cover"/>
</opf:guide>
</opf:package>
`
I know I can get the image by reader.getCoverImage(),
but how about the file name,
if we don't know the file extension, reader.getCoverImage() is useless.
can you add a method to return the cover image file name?
It will be useful to have possibility to build project via some build tool.
please change the method setFullContent to support java.io.File, thanks.
Reader reader = new Reader();
reader.setMaxContentPerSection(1000); // Max string length for the current page.
reader.setIsIncludingTextContent(true); // Optional, to return the tags-excluded version.
reader.setFullContent(new File(epubFilePath)); // Must call before readSection.
Try to switch pages with
bookSection = reader.readSection(5);
And get some trouble -com.github.mertakdut.exception.OutOfPagesException: Out of bounds at position: 4
I don't think that book got only 4 sections
Why so ?
At the beginning of fillNavPoints function, the following statement clears all previously generated navPoints if this is a recursive call:
this.navPoints = new ArrayList<>();
Recursive call of fillNavPoints happens when there are more than one level of TOC.
Is it possible to search text in epub with this library?
App crashes on the version below 19 KitKat but working as expected on version >19
following is the crash report
Caused by: java.lang.NoClassDefFoundError: java.nio.charset.StandardCharsets
at com.github.mertakdut.ContextHelper.encodeToUtf8(ContextHelper.java:26)
at com.github.mertakdut.Reader.mergeTocElements(Reader.java:266)
at com.github.mertakdut.Reader.fillContent(Reader.java:162)
at com.github.mertakdut.Reader.setInfoContent(Reader.java:32)
at com.github.epubparsersampleandroidapplication.MenuActivity$ListBookInfoTask.doInBackground(MenuActivity.java:67)
at com.github.epubparsersampleandroidapplication.MenuActivity$ListBookInfoTask.doInBackground(MenuActivity.java:50)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:838)
Hello
I am making an app for reading EPUB books. when i want to call reader.setFullContent(file.absolutePath) method gives me the following error:
javax.xml.parsers.ParserConfigurationException: http://apache.org/xml/features/nonvalidating/load-dtd-grammar W/System.err: at org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl.setFeature(DocumentBuilderFactoryImpl.java:101) at com.github.mertakdut.Reader.fillContent(Reader.java:322) at com.github.mertakdut.Reader.setFullContentWithProgress(Reader.java:65) at ru.fillipok.reader.ui.fragments.show.ShowActivity.onCreate(ShowActivity.kt:171) at android.app.Activity.performCreate(Activity.java:8086) at android.app.Activity.performCreate(Activity.java:8074) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1313) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3755) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3961) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:91) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386) at android.os.Handler.dispatchMessage(Handler.java:107) W/System.err: at android.os.Looper.loop(Looper.java:213) at android.app.ActivityThread.main(ActivityThread.java:8178) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
Can you please tell me what to do!
Does this lib has the means to manipulate the epub..such as :font size changes , and page manipulation like seek bar changing pages ? for android
EPub URL - https://github.com/IDPF/epub3-samples/releases/download/20170606/childrens-literature.epub
In this epub the first page is cover image which looks good in other epub reader but when I am using this in EPubParser then it shows broken image which can't be rendered - Tested on Pixel 2 XL
reader.setFullContent("android.resource://" + getPackageName() + "/" + "harry.epub");
at the above line i get this exception. There is an absolute absence of information about it in Google. I need your help badly:
04-25 12:10:20.139 13561-13561/com.example.vazil.learnersreader W/System.err: com.github.mertakdut.exception.ReadingException: Error initializing ZipFile: File too short to be a zip file: 0
at com.github.mertakdut.Reader.fillContent(Reader.java:296)
at com.github.mertakdut.Reader.setFullContent(Reader.java:54)
at com.example.vazil.learnersreader.MainActivity.onCreate(MainActivity.java:68)
at android.app.Activity.performCreate(Activity.java:6915)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
I'm looking for a way to get the total size of a book so I can create a simple progress dialog. Here is what I have tried but it is painfully inefficient and slow:
private int getBookContentLength() {
int count = 0;
try {
for (int i = 0; i < Integer.MAX_VALUE; i++) {
count = count + reader.readSection(i).getSectionContent().length();
}
} catch (OutOfPagesException e) {
return count;
} catch (ReadingException e) {
e.printStackTrace();
}
return count;
}
Do you plan on implementing something similar or do you know of a better way? Thanks.
I tried to use the library according to the guideline on the GitHub page
The first problem I got is that there is no class called Book.
The fifth line of code in the Usage section tries to create a Book object from reader.readSection
. I thought maybe you meant to say BookSection
so I replaced it.
And further into the code reader.setFullContent(epubFilePath);
throws the following exception. (I have put the complete stack trace)
What I understood while debugging is that the DocumentBuilderFactoryImpl
class throws ParserConfigurationException
if instance of DocumentBuilderFactoryImpl
calls setFeature with names different from http://xml.org/sax/features/namespaces
and http://xml.org/sax/features/validation
Is there a problem with my android depedencies?
javax.xml.parsers.ParserConfigurationException: http://apache.org/xml/features/nonvalidating/load-dtd-grammar
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl.setFeature(DocumentBuilderFactoryImpl.java:101)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at com.github.mertakdut.Reader.fillContent(Reader.java:98)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at com.github.mertakdut.Reader.setFullContent(Reader.java:39)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at com.a360ground.lomibooksrecycler.BookReaderActivity.onCreate(BookReaderActivity.java:31)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.app.Activity.performCreate(Activity.java:6178)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2648)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.app.ActivityThread.access$900(ActivityThread.java:177)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1430)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.os.Looper.loop(Looper.java:135)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5910)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at java.lang.reflect.Method.invoke(Native Method)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
11-02 12:02:21.755 29673-29673/com.a360ground.lomibooksrecycler W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
Is there any way I can omit the title from getSectionContent() ?
I think it would be better if the title was optional or removed entirely to provide a more immersive reading experience.
Love your work, very useful and really great!
how can i navigate to specified page on clicking from table of content , it gives me issue and ,when i unzip the epub file and like its location like this webView.loadDataWithBaseURL(location, sectionContent, "text/html", "UTF-8", null); it works but it loads full book again in vertical scrolling, not as sections.
how do i redirect to correct page index ( bookSection = reader.readSection(pageIndex); ) on clicking on item from table of contents?
Got some problem with some epubs. Can't read content. Always get only 2-3 words from book. How I can solve it ? (Exmple of such epub)The_Swift_Programming_Language.zip
how to read all chapters title?
thanks.
http://dl.iteye.com/topics/download/ab094932-668a-3f27-99c8-a5a1d698038d
please download this epub file and parse it,
it will throw com.github.mertakdut.exception.ReadingException: toc.ncx not found.
please check and fix it, thanks.
com.github.mertakdut.exception.ReadingException: toc.ncx not found.
at com.github.mertakdut.Reader.fillContent(Reader.java:382)
at com.github.mertakdut.Reader.setFullContent(Reader.java:60)
I am using it, but it does not support Android 11 12, Because the read and write permissions are restricted
I try to manipulate epub file content. But I failed. I achived to open and read epub file. Then I get the text content and change some text. And I rewrite changed text by using setSectionText function. But it doesn't work.
```
Reader reader = new Reader();
reader.setMaxContentPerSection(1000); // Max string length for the current page.
reader.setIsIncludingTextContent(true); // Optional, to return the tags-excluded version.
reader.setFullContent("my_file_path");
BookSection bookSection = reader.readSection(4);
String sectionContent = bookSection.getSectionContent(); // Returns content as html.
String sectionTextContent = bookSection.getSectionTextContent(); // Excludes html tags.
sectionTextContent = sectionTextContent.replaceAll("text", "manipulatedText");
bookSection.setSectionTextContent(sectionTextContent);
reader.saveProgress();
if (reader.isSavedProgressFound()) { // Available after calling setFullContent method.
reader.loadProgress();
}
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.