Struct epub_builder::EpubBuilder [] [src]

pub struct EpubBuilder<Z: Zip> { /* fields omitted */ }

Epub Builder

The main struct you'll need to use in this library. It is first created using a wrapper to zip files; then you add content to it, and finally you generate the EPUB file by calling the generate method.

use epub_builder::EpubBuilder;
use epub_builder::ZipCommand;
use std::io;

// "Empty" EPUB file
let mut builder = EpubBuilder::new(ZipCommand::new().unwrap()).unwrap();
builder.metadata("title", "Empty EPUB").unwrap();
builder.generate(&mut io::stdout()).unwrap();

Methods

impl<Z: Zip> EpubBuilder<Z>
[src]

[src]

Create a new default EPUB Builder

Important traits for &'a mut W
[src]

Set EPUB version (default: V20)

Supported versions are:

  • V20: EPUB 2.0.1
  • 'V30`: EPUB 3.0.1

[src]

Set some EPUB metadata

Valid keys used by the EPUB builder

  • author: author(s) of the book;
  • title: title of the book;
  • lang: the language ot the book, quite important as EPUB renderers rely on it for e.g. hyphenating words.
  • generator: generator of the book (should be your program name);
  • toc_name: the name to use for table of contents (by default, "Table of Contents");
  • subject;
  • description;
  • license.

[src]

Sets stylesheet of the EPUB.

This content will be written in a stylesheet.css file; it is used by some pages (such as nav.xhtml), you don't have use it in your documents though it makes sense to also do so.

Important traits for &'a mut W
[src]

Adds an inline toc in the document.

If this method is called it adds a page that contains the table of contents that appears in the document.

The position where this table of contents will be inserted depends on when you call this method: if you call it before adding any content, it will be at the beginning, if you call it after, it will be at the end.

[src]

Add a resource to the EPUB file

This resource be a picture, a font, some CSS file, .... Unlike add_content, files added this way won't appear in the linear document.

Note that these files will automatically be inserted into an OEBPS directory, so you don't need (and shouldn't) prefix your path with OEBPS/.

Arguments

  • path: the path where this file will be writen in the EPUB OEBPS structure, e.g. data/image_0.png
  • content: the resource to include
  • mime_type: the mime type of this file, e.g. "image/png".

[src]

Add a cover image to the EPUB.

This works similarly to adding the image as a resource with the add_resource method, except, it signals it in the Manifest secton so it is displayed as the cover by Ereaders

[src]

Add a XHTML content file that will be added to the EPUB.

Examples

let content = "Some content";
let mut builder = EpubBuilder::new(ZipLibrary::new().unwrap()).unwrap();
// Add a chapter that won't be added to the Table of Contents
builder.add_content(EpubContent::new("intro.xhtml", content.as_bytes())).unwrap();
// Sets the title of a chapter so it is added to the Table of contents
// Also add information about its structure
builder.add_content(EpubContent::new("chapter_1.xhtml", content.as_bytes())
                     .title("Chapter 1")
                     .child(TocElement::new("chapter_1.xhtml#1", "1.1"))).unwrap();
// Add a section, by setting the level to 2 (instead of the default value 1)
builder.add_content(EpubContent::new("section.xhtml", content.as_bytes())
                     .title("Section 1")
                     .level(2)).unwrap();

Note that these files will automatically be inserted into an OEBPS directory, so you don't need (and shouldn't) prefix your path with OEBPS/.

See also

  • EpubContent
  • the add_resource method, to add other resources in the EPUB file.

[src]

Generate the EPUB file and write it to the writer

Example

let mut builder = EpubBuilder::new(ZipLibrary::new().unwrap()).unwrap();
// Write the EPUB file into a Vec<u8>
let mut epub: Vec<u8> = vec!();
builder.generate(&mut epub).unwrap();

Trait Implementations

impl<Z: Debug + Zip> Debug for EpubBuilder<Z>
[src]

[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<Z> Send for EpubBuilder<Z> where
    Z: Send

impl<Z> Sync for EpubBuilder<Z> where
    Z: Sync