Skip to content

asido/EpubSharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

232 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EpubSharp

A C# library for reading and writing EPUB files.

Supported EPUB versions: 2.0, 3.0, 3.1

Overview

EpubSharp provides a simple and efficient way to interact with EPUB files in .NET. It supports reading metadata, table of contents, and internal resources (HTML, CSS, images, fonts) from EPUB 2.0 and 3.x documents.

Requirements

  • SDK: .NET 10.0 or higher
  • Runtime: .NET 8.0, .NET 10.0, or compatible environments

Installation

NuGet

Install the package via the NuGet Package Manager:

dotnet add package EpubSharp.dll

Or via the Package Manager Console:

Install-Package EpubSharp.dll

From Source

  1. Clone the repository.
  2. Build the project:
    dotnet build

Usage

Reading an EPUB

using EpubSharp;

// Read an EPUB file
EpubBook book = EpubReader.Read("my.epub");

// Read metadata
string title = book.Title;
string[] authors = book.Authors;
byte[] coverImage = book.CoverImage; // Note: Returns byte array in recent versions

// Get table of contents
ICollection<EpubChapter> chapters = book.TableOfContents;

// Get contained files
ICollection<EpubTextFile> html = book.Resources.Html;
ICollection<EpubTextFile> css = book.Resources.Css;
ICollection<EpubByteFile> images = book.Resources.Images;
ICollection<EpubByteFile> fonts = book.Resources.Fonts;

// Convert to plain text
string text = book.ToPlainText();

// Access internal EPUB format specific data structures
EpubFormat format = book.Format;
OcfDocument ocf = format.Ocf;
OpfDocument opf = format.Opf;
NcxDocument ncx = format.Ncx;
NavDocument nav = format.Nav;

Writing an EPUB

Warning

Editing capabilities are currently very limited and might not work at all. Use it at your own risk.

using EpubSharp;

EpubWriter writer = new EpubWriter();

writer.AddAuthor("Foo Bar");
writer.SetCover(imgData, ImageFormat.Png);

writer.Write("new.epub");

Scripts & Commands

The project uses the standard .NET CLI:

  • Build: dotnet build
  • Test: dotnet test
  • Pack: dotnet pack (generates NuGet package in bin/Debug or bin/Release)

Project Structure

  • EpubSharp/: Core library containing EPUB parsing and writing logic.
    • Format/: Readers and writers for OPF, NCX, NAV, and OCF documents.
    • Extensions/: Helper methods for zip archives, streams, and XML.
  • EpubSharp.Tests/: xUnit test suite with sample EPUB files.

Environment Variables

No specific environment variables are required for this library.

License

This project is licensed under the Mozilla Public License 2.0 (MPL-2.0). See the LICENSE file for details.

TODOs

  • Complete full write support for EPUB 3.x.
  • Improve documentation for internal data structures.
  • Add more comprehensive integration tests with various EPUB samples.

About

C# library for reading EPUB file format

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages