All formats

QuickEPUB

LanguageC# (.NET Standard 2.0)
LicenseMIT
Repositorygithub.com/jonthysell/QuickEPUB
DocumentationREADME
Depends onnothing outside .NET
Read / writeno / yes

QuickEPUB creates simple EPUB books without requiring you to know the EPUB structure. You give it a title, an author and a list of HTML sections; it generates the mimetype file, container.xml, the OPF package, the navigation document and table of contents, and zips everything correctly. Each section becomes one chapter and one entry in the table of contents.

It’s meant for exporting content from an app (notes, articles, reports) as an e-book. It doesn’t read EPUB files and has no options for nested tables of contents, fixed layout or detailed metadata. For those, generate the files yourself or use a fuller library in another language.

Installation#

Shell
dotnet add package QuickEPUB

Basic usage: create an EPUB#

C#
using QuickEPUB;

var doc = new Epub("My Book", "Jane Doe");
doc.Language = "en";
doc.UID = "urn:uuid:" + Guid.NewGuid();

doc.AddSection("Chapter 1", "<p>It was a bright cold day in April.</p>");
doc.AddSection("Chapter 2", "<p>The second chapter.</p>");

using var fs = new FileStream("book.epub", FileMode.Create);
doc.Export(fs);

How to add images to an EPUB#

Reference the image in the section HTML, then add the file as a resource with the same path:

C#
doc.AddSection("Pictures", "<p><img src=\"photo.jpg\" alt=\"A photo\"/></p>");

using (var img = new FileStream("photo.jpg", FileMode.Open))
{
    doc.AddResource("photo.jpg", EpubResourceType.JPEG, img);
}

How to set a cover image#

Pass isCover: true when adding the image resource:

C#
using (var cover = new FileStream("cover.jpg", FileMode.Open))
{
    doc.AddResource("cover.jpg", EpubResourceType.JPEG, cover, isCover: true);
}

How to style chapters with CSS#

The third argument of AddSection is the path of a stylesheet resource:

C#
doc.AddSection("Chapter 3", "<p class=\"intro\">Styled text.</p>", "book.css");

using (var css = new FileStream("book.css", FileMode.Open))
{
    doc.AddResource("book.css", EpubResourceType.CSS, css);
}

Tips#