Comments (1)
It is possible. Anything you are going to use in the CSS files (fonts, images, ...) you can add to the book as ebooklib.epub.EpubItem
with proper name and media type. This will create correct metadata in the EPUB to embed the files in the EPUB file.
For instance:
name = os.path.basename(font_name)
extension = os.path.splitext(font_name)[-1].lower()
font = ebooklib.epub.EpubItem()
font.file_name = "{}/{}".format(FONTS_DIR, name)
font.set_content(content)
# try to set the right font media type
# http://www.idpf.org/epub/301/spec/epub-publications.html#sec-core-media-types
if extension in self.OPENTYPE_FONTS:
font.media_type = 'application/vnd.ms-opentype'
elif extension in self.WOFF_FONTS:
font.media_type = 'application/font-woff'
epub_book.add_item(font)
And then you need to add CSS to each chapter (ebooklib.epub.EpubHtml
). This will create correct tags in the header of the chapter. The best way to do it is maybe write plugin which would do it for you (so you don't have to do it for each file). Check the link bellow and wirterplugins/base_writerplugin.py we used for themes.
Booktype was the software for which the library was developed and you can check here in the method _add_theme_assets
how it is done. You can check how the Covers and other stuff is managed. Would be good to add this to the documentation.
https://github.com/booktype/Booktype/blob/master/lib/booktype/convert/epub/converter.py
from ebooklib.
Related Issues (20)
- loop into epub file and make changes based on pattern .
- How to change the heading of nav page in created epub?
- Library fails to handle epub where some items in content.xml are missing HOT 1
- AttributeError: 'bytes' object has no attribute 'encode'. Did you mean: 'decode'? HOT 2
- Slashes in TOC file paths are converted to backslashes in EpubNav (on Windows) HOT 3
- Epub not showing up on kindle HOT 2
- Cant write epub HOT 1
- broken chapters in an ebook HOT 4
- Images not shown between pages HOT 5
- 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?
- Write ebook file directly into db instead file HOT 1
- Warning on opening ebook HOT 1
- [element "ol" incomplete; missing required element "li"] in [nav.xhtml] when creating epub with nested directories HOT 2
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.