Introduction paragraph where i explain what is happening.
' + c1.set_content(u'Introduction paragraph where i explain what is happening.
') # about chapter c2 = epub.EpubHtml(title='About this book', file_name='about.xhtml') - c2.content='Helou, this is my book! There are many books, but this one is mine.
' + c2.content.write(b'Helou, this is my book! There are many books, but this one is mine.
') # add chapters to the book book.add_item(c1) diff --git a/samples/02_cover_create/create.py b/samples/02_cover_create/create.py index ee3cf75..ab42f27 100644 --- a/samples/02_cover_create/create.py +++ b/samples/02_cover_create/create.py @@ -18,11 +18,11 @@ # intro chapter c1 = epub.EpubHtml(title='Introduction', file_name='intro.xhtml', lang='hr') - c1.content=u'Introduction paragraph where i explain what is happening.
' + c1.set_content(u'Introduction paragraph where i explain what is happening.
') # about chapter c2 = epub.EpubHtml(title='About this book', file_name='about.xhtml') - c2.content='Helou, this is my book! There are many books, but this one is mine.
' + c2.content.write(b'Helou, this is my book! There are many books, but this one is mine.
') # add chapters to the book book.add_item(c1) diff --git a/samples/03_advanced_create/create.py b/samples/03_advanced_create/create.py index 909046b..52b8533 100644 --- a/samples/03_advanced_create/create.py +++ b/samples/03_advanced_create/create.py @@ -15,7 +15,7 @@ # intro chapter c1 = epub.EpubHtml(title='Introduction', file_name='intro.xhtml', lang='hr') - c1.content=u'Introduction paragraph where i explain what is happening.
' + c1.set_content(u'Introduction paragraph where i explain what is happening.
') # defube style style = '''BODY { text-align: justify;}''' @@ -26,7 +26,7 @@ # about chapter c2 = epub.EpubHtml(title='About this book', file_name='about.xhtml') - c2.content='Helou, this is my book! There are many books, but this one is mine.
' + c2.write('Helou, this is my book! There are many books, but this one is mine.
') c2.set_language('hr') c2.properties.append('rendition:layout-pre-paginated rendition:orientation-landscape rendition:spread-none') c2.add_item(default_css) diff --git a/samples/04_markdown_parse/epub2markdown.py b/samples/04_markdown_parse/epub2markdown.py index 19df3e1..939192c 100755 --- a/samples/04_markdown_parse/epub2markdown.py +++ b/samples/04_markdown_parse/epub2markdown.py @@ -20,11 +20,11 @@ proc = subprocess.Popen(['pandoc', '-f', 'html', '-t', 'markdown', '-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) - content, error = proc.communicate(item.content) + content, error = proc.communicate(item.get_content()) file_name = os.path.splitext(item.file_name)[0] + '.md' else: file_name = item.file_name - content = item.content + content = item.get_content() # create needed directories dir_name = '{0}/{1}'.format(base_name, os.path.dirname(file_name)) diff --git a/samples/07_pagebreaks/create.py b/samples/07_pagebreaks/create.py index 9c6ad52..378a145 100644 --- a/samples/07_pagebreaks/create.py +++ b/samples/07_pagebreaks/create.py @@ -17,22 +17,22 @@ # build the chapter HTML and add the page break c1 = epub.EpubHtml(title='Introduction', file_name='intro.xhtml', lang='en') - c1.content = u'1This chapter has a visible page number.
2Something else now.
' + c1.set_content(u'1This chapter has a visible page number.
2Something else now.
') c2 = epub.EpubHtml(title='Chapter the Second', file_name='chap02.xhtml', lang='en') - c2.content = u'This chapter has two page breaks, both with invisible page numbers.
' + c2.content.write(u'This chapter has two page breaks, both with invisible page numbers.
'.encode()) # Add invisible page numbers that match the printed text, for accessibility - c2.content += create_pagebreak("2") + c2.write(create_pagebreak("2")) # You can add more content after the page break - c2.content += u'This is the second page in the second chapter, after the invisible page break.
' + c2.write(u'This is the second page in the second chapter, after the invisible page break.
') # Add invisible page numbers that match the printed text, for accessibility - c2.content += create_pagebreak("3", label="Page 3") + c2.write(create_pagebreak("3", label="Page 3")) # close the chapter - c2.content += u'' + c2.write(u'') # add chapters to the book book.add_item(c1) diff --git a/samples/10_large_files/README.md b/samples/10_large_files/README.md new file mode 100644 index 0000000..4ce1066 --- /dev/null +++ b/samples/10_large_files/README.md @@ -0,0 +1,8 @@ +Large create +============ + +Creates LARGE EPUB files + +## Start + + python create.py \ No newline at end of file diff --git a/samples/10_large_files/create.py b/samples/10_large_files/create.py new file mode 100644 index 0000000..bf4391e --- /dev/null +++ b/samples/10_large_files/create.py @@ -0,0 +1,87 @@ +# coding=utf-8 + +from ebooklib import epub +from tempfile import TemporaryFile + + +if __name__ == '__main__': + book = epub.EpubBook() + + # add metadata + book.set_identifier('sample123456') + book.set_title('Sample book') + book.set_language('en') + + book.add_author('Aleksandar Erkalovic') + + # intro chapter + c1 = epub.EpubHtml(title='Introduction', file_name='intro.xhtml', lang='en') + c1.set_content(u'Introduction paragraph where i explain what is happening.
') + + # about chapter + c2 = epub.EpubHtml(title='About this book', file_name='about.xhtml', content=TemporaryFile()) + c2.write('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin rutrum erat ipsum, at fringilla sem sodales ut. Donec rutrum condimentum leo, non convallis ipsum sodales vel. Sed vulputate, quam dapibus pharetra viverra, nunc magna fermentum ligula, sed placerat enim diam id nisi. Sed justo nunc, placerat vel rutrum eget, lacinia quis ante. Maecenas semper turpis lectus, sed sollicitudin diam feugiat vitae. Mauris massa felis, cursus non enim a, consequat pulvinar mauris. Proin scelerisque neque felis, in fringilla ligula tristique ac. Phasellus interdum lacus neque, ac efficitur nibh consequat a. Donec enim enim, commodo sed finibus in, dignissim sit amet arcu. Nam mollis eu ipsum sed ornare. Maecenas non ipsum molestie, volutpat nulla quis, accumsan arcu. Cras imperdiet augue interdum ipsum laoreet malesuada vitae consectetur ipsum. Quisque vitae tortor augue.
') + + # add chapters to the book + book.add_item(c1) + book.add_item(c2) + + # create table of contents + # - add section + # - add auto created links to chapters + + book.toc = (epub.Link('intro.xhtml', 'Introduction', 'intro'), + (epub.Section('Languages'), + (c1, c2)) + ) + + # add navigation files + book.add_item(epub.EpubNcx()) + book.add_item(epub.EpubNav()) + + # define css style + style = ''' +@namespace epub "http://www.idpf.org/2007/ops"; + +body { + font-family: Cambria, Liberation Serif, Bitstream Vera Serif, Georgia, Times, Times New Roman, serif; +} + +h2 { + text-align: left; + text-transform: uppercase; + font-weight: 200; +} + +ol { + list-style-type: none; +} + +ol > li:first-child { + margin-top: 0.3em; +} + + +nav[epub|type~='toc'] > ol > li > ol { + list-style-type:square; +} + + +nav[epub|type~='toc'] > ol > li > ol > li { + margin-top: 0.3em; +} + +''' + + # add css file + nav_css = epub.EpubItem(uid="style_nav", file_name="style/nav.css", media_type="text/css", content=style) + book.add_item(nav_css) + + # create spine + book.spine = ['nav', c1, c2] + + # create epub file + epub.write_epub('test.epub', book, {}) +