Comments (5)
In your files like f"{OUTPUT_FOLDER}/section_0.xhtml" do you reference your images with something like ? You create image object and you add it to the book, which is all ok, but then that image has to be references in CSS or HTML files somehow.
from ebooklib.
Thanks! I'm going to try. 🙏
from ebooklib.
Hi, I'm here again.
I tried to put img tag in .xhtml file that contains text too.
Checking the .xhtml on browser the image is visible file but not in epub.
c_content = open(f"{OUTPUT_FOLDER}/section_{chapter['BookSectionId']}_{str(i)}.xhtml", "rb").read()
c = epub.EpubHtml(title=f"{chapter['BookChapter']}:{paragraph['BookParagraph']}", file_name=f"section_{chapter['BookSectionId']}_{str(i)}.xhtml", content=c_content)
c.set_language(data['BookLanguage'])
c.properties.append('rendition:layout-pre-paginated rendition:orientation-landscape rendition:spread-none')
c.add_item(default_css)
from ebooklib.
I've just tried as example (I suppose), but images are not shown.
In both, the the size of epub is the same 46Mb but images are not shown. They are in PNG format
els = []
book_toc = [epub.Link("preface.xhtml", "Prefazione", "prefazione")]
for chapter in data['Chapters']:
for i, paragraph in enumerate(chapter['BookParagraphs']):
print(chapter['BookSectionId'])
# image_content0 = open(f'{IMAGES_FOLDER}/section_0.png', 'rb').read()
# img0 = epub.EpubImage(uid='image_0', file_name='static/section_0.jpg', media_type='image/jpg', content=image_content0)
# chapter with image
c1 = epub.EpubHtml(title=f"{chapter['BookChapter']}:{paragraph['BookParagraph']}", file_name=f"section_{chapter['BookSectionId']}_{str(i)}_img.xhtml")
c1.set_language(data['BookLanguage'])
c1.content = u'''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>''' + chapter['BookChapter'] + '''</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="style.css" type="text/css" />
<style>
h1 {
text-align: center;
font-variant: small-caps;
margin-top: 1em;
margin-bottom: 1em;
}
h2, h3, h4 {
text-align: left;
font-variant: small-caps;
margin-top: 1em;
margin-bottom: 1em;
}
a.noteref {
vertical-align: super;
position: relative;
bottom: 0.5em;
font-size: small;
}
p.note {
text-indent: 0px;
margin-top: 0.4em;
margin-left: 0.2em;
font-size: 0.9em;
}
p.center {
text-align: center;
}
p.right {
text-align: right;
}
p.comment {
margin-top: 1em;
margin-bottom: 1em;
margin-left: 4em;
margin-right: 8em;
font-size: 0.9em;
font-style: italic;
}
p.noindent {
text-indent: 0px;
}
</style>
</head>
<body>
<img src = "''' + f"{OUTPUT_FOLDER}/images/c{str(chapter['BookSectionId'])}_p{str(i)}.png" + '''" alt = "" srcset = "" / >
</body>
</html>
'''
# chapter with image
image_content = open(f"{OUTPUT_FOLDER}/images/c{str(chapter['BookSectionId'])}_p{str(i)}.png", 'rb').read()
img = epub.EpubImage(uid=f"image_c{str(chapter['BookSectionId'])}_p{str(i)}", file_name=f"images/c{str(chapter['BookSectionId'])}_p{str(i)}.png", media_type='image/png', content=image_content)
els.append(c1)
els.append(img)
# chapter
c_content = open(f"{OUTPUT_FOLDER}/section_{chapter['BookSectionId']}_{str(i)}.xhtml", "rb").read()
c = epub.EpubHtml(title=f"{chapter['BookChapter']}:{paragraph['BookParagraph']}", file_name=f"section_{chapter['BookSectionId']}_{str(i)}.xhtml", content=c_content)
c.set_language(data['BookLanguage'])
c.properties.append('rendition:layout-pre-paginated rendition:orientation-landscape rendition:spread-none')
c.add_item(default_css)
els.append(c)
book_toc.append(epub.Link(f"section_{chapter['BookSectionId']}_{str(i)}.xhtml", chapter['BookChapter'],
f"{chapter['BookChapter']}_{paragraph['BookParagraph']}".lower().replace(' ', '').replace(':', '_')))
book.add_item(p1)
for el in els:
book.add_item(el)
# create table of contents
# - add manual link
# - add section
# - add auto created links to chapters
book.toc = tuple(book_toc)
from ebooklib.
Hi.
Ok it works, but how can I center image horizontally?
I've tried this
img {
max-width: 100% !important;
max-height: 100% !important;
display: block !important;
text-align: center !important;
margin: auto !important;
}
from ebooklib.
Related Issues (20)
- broken chapters in an ebook HOT 4
- Get page as image HOT 3
- In some HTML elements, attribute names need to be case-sensitive to take effect, for example, the viewBox attribute within the <svg> element.
- Option ignore_ncx (warning) HOT 3
- Saving with `set_content` produces empty HTML HOT 1
- Is there any plan on typing supports?
- Can't change the metadata
- Non-image cover?
- Include a font file, or any arbitrary file? HOT 1
- Write ebook file directly into db instead file HOT 1
- Warning on opening ebook HOT 2
- [element "ol" incomplete; missing required element "li"] in [nav.xhtml] when creating epub with nested directories HOT 2
- nsmap = metadata.nsmap HOT 1
- epub does not function with Kivy HOT 4
- item.get_type() does not recognize webm HOT 1
- write_epub() is deleting the css link HOT 3
- Unable to get my epub read on google play books! HOT 3
- Non-linear content must be reachable
- Reflection HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ebooklib.