diff --git a/src/calibre/ebooks/epub/from_html.py b/src/calibre/ebooks/epub/from_html.py
index 2adef2bb3a..fb37c25893 100644
--- a/src/calibre/ebooks/epub/from_html.py
+++ b/src/calibre/ebooks/epub/from_html.py
@@ -145,6 +145,20 @@ def resize_cover(im, opts):
im = im.resize((int(nwidth), int(nheight)), PILImage.ANTIALIAS)
return im
+TITLEPAGE = '''\
+
+
+ Cover
+
+
+
+
+

+
+
+
+'''
+
def process_title_page(mi, filelist, htmlfilemap, opts, tdir):
old_title_page = None
f = lambda x : os.path.normcase(os.path.normpath(x))
@@ -188,19 +202,7 @@ def process_title_page(mi, filelist, htmlfilemap, opts, tdir):
cover = metadata_cover if specified_cover is None or (opts.prefer_metadata_cover and metadata_cover is not None) else specified_cover
if hasattr(cover, 'save'):
- titlepage = '''\
-
-
- Cover
-
-
-
-
-

-
-
-
- '''%cpath
+ titlepage = TITLEPAGE%cpath
tp = 'calibre_title_page.html' if old_title_page is None else old_title_page
tppath = os.path.join(tdir, 'content', tp)
with open(tppath, 'wb') as f:
diff --git a/src/calibre/ebooks/epub/iterator.py b/src/calibre/ebooks/epub/iterator.py
index 3c053f1780..7702d75769 100644
--- a/src/calibre/ebooks/epub/iterator.py
+++ b/src/calibre/ebooks/epub/iterator.py
@@ -8,6 +8,7 @@ Iterate over the HTML files in an ebook. Useful for writing viewers.
import re, os, math, copy
from calibre.ebooks.epub.from_any import MAP
+from calibre.ebooks.epub.from_html import TITLEPAGE
from calibre.ebooks.epub import config
from calibre.ebooks.metadata.opf2 import OPF
from calibre.ptempfile import TemporaryDirectory
@@ -83,16 +84,28 @@ class EbookIterator(object):
self.pathtoopf = self.to_opf(self.pathtoebook, self.base, opts)
self.opf = OPF(self.pathtoopf, os.path.dirname(self.pathtoopf))
self.spine = [SpineItem(i.path) for i in self.opf.spine]
+
+ cover = self.opf.cover
+ if os.path.splitext(self.pathtoebook)[1].lower() in ('.lit', '.mobi', '.prc') and cover:
+ cfile = os.path.join(os.path.dirname(self.spine[0]), 'calibre_ei_cover.html')
+ open(cfile, 'wb').write(TITLEPAGE%cover)
+ self.spine[0:0] = [SpineItem(cfile)]
+
sizes = [i.character_count for i in self.spine]
self.pages = [math.ceil(i/float(self.CHARACTERS_PER_PAGE)) for i in sizes]
for p, s in zip(self.pages, self.spine):
s.pages = p
start = 1
+
+
for s in self.spine:
s.start_page = start
start += s.pages
s.max_page = s.start_page + s.pages - 1
self.toc = self.opf.toc
+
+
+
return self
def __exit__(self, *args):