Closed ghost closed 4 months ago
Check the samples/02_cover_create/create.py. You don't need to create cover page (if it is just image on the cover):
book.set_cover("cover.jpg", cover_content, create_page=True)
This is the template for the cover page:
COVER_XML = six.b('''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="en" xml:lang="en">
<head>
<style>
body { margin: 0em; padding: 0em; }
img { max-width: 100%; max-height: 100%; }
</style>
</head>
<body>
<img src="" alt="" />
</body>
</html>''')
This should do the trick and you can just add 'cover' to the spine (like in the sample). Did you tried to use epubcheck tool to validate your EPUB file?
That being said, I noticed now that sample creates EPUB which fails with epubcheck 5.0 and EPUB 3.3. Just created new ticket (#315 ) for it and will take a look at it tomorrow.
Aco
Hi,
Thank you for the information.
Simply changing the name "cover.xhtml" to something else resolved the issue for me. Could it be that there's something on epub's 3.3 side already using the cover as name?
def write_cover_page(self):
self.cover_page = epub.EpubHtml(title="Cover Page", file_name="cover.xhtml")
self.cover_page.content = ( f"<img src='cover.jpeg'/>" )
self.book.add_item(self.cover_page)
def write_cover_page(self):
self.cover_page = epub.EpubHtml(title="Cover Page", file_name="titlepage.xhtml")
self.cover_page.content = (f"<img src='cover_image.jpeg'/>")
self.book.add_item(self.cover_page)
Yes, when you call book.set_cover() it will create page with id="cover" and file_name="cover.xhtml". So in your case you don't need to create separate cover page.
Also, if you will have some issues with some checks according to the specs you would need to have cover page mentioned somewhere in the content or inside your TOC. In that case just fetch that page and insert it. For instance:
cover = book.get_item_with_id('cover')
book.toc = (
cover,
epub.Link('intro.xhtml', 'Introduction', 'intro'),
(epub.Section('Languages'),
(c1, c2)
)
)
For some reason, when I add the cover to the spine, the EPUB doesn't work on Google Play Books. It works on all other EPUB readers except Google Play Books. This might be related to EPUB 2 support. However, if I convert the EPUB to another format using Calibre and then convert it back to EPUB, it updates correctly. Additionally, if I remove the "self.cover_page" from the spine, it also works.
In the momment i run this function, it doesn't work anymore if you comment it, it works
I also get this error that i'm not actually sure how to fix when the self.cover_page is on the spine and the function is ran