Git Product home page Git Product logo

Comments (5)

aerkalov avatar aerkalov commented on August 15, 2024

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.

ianustec avatar ianustec commented on August 15, 2024

Thanks! I'm going to try. 🙏

from ebooklib.

ianustec avatar ianustec commented on August 15, 2024

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.

ianustec avatar ianustec commented on August 15, 2024

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.

ianustec avatar ianustec commented on August 15, 2024

Hi.

Ok it works, but how can I center image horizontally?

https://ibb.co/zNwLBCH

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)

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.