bell notificationshomepageloginedit profileclubsdmBox

10.01% popularity   0 Reactions

I have an epub file which has n number of chapters. I have to copy or extract up to 1 chapter and make a new epub file which contains only 1 chapter in order to show a sample file which contains only one chapter to the user. If the user purchases the book I need to show the original book.

I know epub.js viewer, but how can I meet the above requirement with PHP and jQuery/JavaScript and also with any other language like .net, Java, or Python, etc.? Any suggestions?


Free books android app tbrJar TBR JAR Read Free books online gutenberg


Load Full (1)

Login to follow story

More posts by @Carla

1 Comments

Sorted by latest first Latest Oldest Best

10% popularity   0 Reactions

An EPUB file consists of multiple entries in a ZIP file. To extract the first chapter, you have to first determine how you know where the second chapter starts, as this doesn't have to coincide with an entry in the ZIP file.

Essentially what you need to do is:

Extract and analyse "META-INF/container.xml" to determine where is the root content file of the document which can be in the root of the EPUB, but also in a subdirectory)
Walk over the items in the content file to start building up the first chapter and accumulate data until you hit the second chapter.
On the way there you might have to take care of included images, cross references and the like.

Once you have gathered this data, write out the first chapter into a new file. Care should be taken this is a valid EPUB file, that adheres to the restrictions on EPUB entry sizes that some older readers impose (i.e. split the HTML for the first chapter in small enough chunks). Any language with a good XML library (including namespaces), HTML parsing and a handling zip files should do the job. I tend to use Python for that.


Free books android app tbrJar TBR JAR Read Free books online gutenberg


Load Full (0)

 

Back to top