QuickEPUB
| Language | C# (.NET Standard 2.0) |
|---|---|
| License | MIT |
| Repository | github.com/jonthysell/QuickEPUB |
| Documentation | README |
| Depends on | nothing outside .NET |
| Read / write | no / 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#
dotnet add package QuickEPUB
Basic usage: create an EPUB#
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:
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:
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:
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#
- Section HTML must be well-formed XHTML: close every tag (
<br/>,<img .../>) and escape&as&, or e-readers will reject the chapter. - Run the result through EPUBCheck to catch markup errors.
- Change the title of the generated table of contents with
doc.TableOfContentsTitle.