GithubHelp home page GithubHelp logo

Comments (1)

aerkalov avatar aerkalov commented on May 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.