Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/tugot17/ebooklib into tug…
Browse files Browse the repository at this point in the history
…ot17-master
  • Loading branch information
aerkalov committed Nov 27, 2022
2 parents 0312548 + 66ccdda commit f718c53
Showing 1 changed file with 92 additions and 83 deletions.
175 changes: 92 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
About EbookLib
==============
# About EbookLib

EbookLib is a Python library for managing EPUB2/EPUB3 and Kindle files. It's capable of reading and writing EPUB files programmatically (Kindle support is under development).

Expand All @@ -11,84 +10,94 @@ Packages of EbookLib for GNU/Linux are available in [Debian](https://packages.de

Sphinx documentation is generated from the templates in the docs/ directory and made available at http://ebooklib.readthedocs.io

Usage
=====

Reading
-------

::

import ebooklib
from ebooklib import epub

book = epub.read_epub('test.epub')

for image in book.get_items_of_type(ebooklib.ITEM_IMAGE):
print image

Writing
-------

::

from ebooklib import epub

book = epub.EpubBook()

# set metadata
book.set_identifier('id123456')
book.set_title('Sample book')
book.set_language('en')

book.add_author('Author Authorowski')
book.add_author('Danko Bananko', file_as='Gospodin Danko Bananko', role='ill', uid='coauthor')

# create chapter
c1 = epub.EpubHtml(title='Intro', file_name='chap_01.xhtml', lang='hr')
c1.content=u'<h1>Intro heading</h1><p>Zaba je skocila u baru.</p><p><img alt="[ebook logo]" src="static/ebooklib.gif"/><br/></p>'

# create image from the local image
image_content = open('ebooklib.gif', 'rb').read()
img = epub.EpubImage(uid='image_1', file_name='static/ebooklib.gif', media_type='image/gif', content=image_content)

# add chapter
book.add_item(c1)
# add image
book.add_item(img)

# define Table Of Contents
book.toc = (epub.Link('chap_01.xhtml', 'Introduction', 'intro'),
(epub.Section('Simple book'),
(c1, ))
)

# add default NCX and Nav file
book.add_item(epub.EpubNcx())
book.add_item(epub.EpubNav())

# define CSS style
style = 'BODY {color: white;}'
nav_css = epub.EpubItem(uid="style_nav", file_name="style/nav.css", media_type="text/css", content=style)

# add CSS file
book.add_item(nav_css)

# basic spine
book.spine = ['nav', c1]

# write to the file
epub.write_epub('test.epub', book, {})



License
=======

EbookLib is licensed under the AGPL license.


Authors
=======

Full list of authors is in AUTHORS.txt file.
# Usage

## Reading
```py
import ebooklib
from ebooklib import epub

book = epub.read_epub('test.epub')

for image in book.get_items_of_type(ebooklib.ITEM_IMAGE):
print(image)
```


## Writing
```py
from ebooklib import epub

book = epub.EpubBook()

# set metadata
book.set_identifier("id123456")
book.set_title("Sample book")
book.set_language("en")

book.add_author("Author Authorowski")
book.add_author(
"Danko Bananko",
file_as="Gospodin Danko Bananko",
role="ill",
uid="coauthor",
)

# create chapter
c1 = epub.EpubHtml(title="Intro", file_name="chap_01.xhtml", lang="hr")
c1.content = (
"<h1>Intro heading</h1>"
"<p>Zaba je skocila u baru.</p>"
'<p><img alt="[ebook logo]" src="static/ebooklib.gif"/><br/></p>'
)

# create image from the local image
image_content = open("ebooklib.gif", "rb").read()
img = epub.EpubImage(
uid="image_1",
file_name="static/ebooklib.gif",
media_type="image/gif",
content=image_content,
)

# add chapter
book.add_item(c1)
# add image
book.add_item(img)

# define Table Of Contents
book.toc = (
epub.Link("chap_01.xhtml", "Introduction", "intro"),
(epub.Section("Simple book"), (c1,)),
)

# add default NCX and Nav file
book.add_item(epub.EpubNcx())
book.add_item(epub.EpubNav())

# define CSS style
style = "BODY {color: white;}"
nav_css = epub.EpubItem(
uid="style_nav",
file_name="style/nav.css",
media_type="text/css",
content=style,
)

# add CSS file
book.add_item(nav_css)

# basic spine
book.spine = ["nav", c1]

# write to the file
epub.write_epub("test.epub", book, {})
```


# License
EbookLib is licensed under the [AGPL license](LICENSE.txt).


# Authors
Full list of authors is in [AUTHORS.txt](AUTHORS.txt) file.

0 comments on commit f718c53

Please sign in to comment.