ebooklib icon indicating copy to clipboard operation
ebooklib copied to clipboard

Rendering of EPUB2/EPUB3 file using Ebooklib

Open DhairyashilBhosale opened this issue 9 years ago • 1 comments

Hi all, Hi I am Dhairyashil, I am new to Epub and python. I am trying to render the Epub2/ Epub3 file in python so while exploring I found about Ebooklib but mostly epub file creation. so I am trying to render EPUB3 file in python App. so can any one please provide me some example or sample code that will give the idea that how to render Epub3 file as per TOC. I didn't get that for rendering which method to call first, how to link TOC with html file using Ebooklib.

So please help me to render EPUB3 file in python using Ebooklib.

DhairyashilBhosale avatar Mar 31 '16 12:03 DhairyashilBhosale

Here is very simple example. It reads .epub file, reads Table Of Contents of the book, fetches each chapter which is listed in TOC and prints contents. To fetch CSS/Images and other things you would need to parse the content, find the images/css and extract it.

It also depends how do you want to render the book? Is it a web page or stand alone GUI application? If it is web you could make it in easier way where you show the content of the chapter, browser will try to fetch attachments and you would catch these requests, use the same get_item_with_href() method to fetch the file and just return it.

Hope it helps a bit or at least puts you in the right direction.

import sys

import ebooklib
from ebooklib import epub

book = epub.read_epub(sys.argv[1])

for a in book.toc:
    item = book.get_item_with_href(a.href)
    print item.get_content()

aerkalov avatar Apr 02 '16 10:04 aerkalov