Coverting epub to html file using pypandoc

Viewed 514
import pypandoc
html=pypandoc.convert_file("corona.epub",'html',outputfile="corona1.html")
assert html==""

I'm tried to convert an epub file into HTML file but the output is only text HTML. there is no image in this file. how to convert HTML with image?

2 Answers

you could use:

$ unzip "corona.epub"

from your command line, and it will expand all the xhtml files inside the epub

import pypandoc
import os

os.environ.setdefault('PYPANDOC_PANDOC', '/opt/homebrew/bin/pandoc')


filepath = "<full path of your epub file...>"
pathname, filename = os.path.split(filepath)
targetfilename = 'index.html'


pypandoc.convert_file(filepath,
                  format='epub',
                  to='html5',
                  extra_args=[
                      '--read=epub',
                      f'--extract-media={pathname}',
                      '--wrap=none'
                  ],
                  encoding='utf-8',
                  outputfile=pathname + '/' + targetfilename,
                  filters=None,
                  verify_format=True
                 )
Related