MyBook.Writer 1.0.1

dotnet add package MyBook.Writer --version 1.0.1
                    
NuGet\Install-Package MyBook.Writer -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MyBook.Writer" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MyBook.Writer" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="MyBook.Writer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MyBook.Writer --version 1.0.1
                    
#r "nuget: MyBook.Writer, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=MyBook.Writer&version=1.0.1
                    
Install MyBook.Writer as a Cake Addin
#tool nuget:?package=MyBook.Writer&version=1.0.1
                    
Install MyBook.Writer as a Cake Tool

MyBook.Writer

A clean, modern library for creating e-books in EPUB and FB2 formats using .NET.

NuGet Build and Publish

Installation

dotnet add package MyBook.Writer

Quick Start

Creating an EPUB Book

// Create a new EPUB builder
var builder = EpubBuilder.Create("My Book Title", "en")
    .WithAuthor("Author Name");

// Add a cover image
using (var coverStream = File.OpenRead("cover.jpg"))
{
    builder.WithCover(coverStream, "cover.jpg", "image/jpeg");
}

// Add chapters
builder.AddChapter(1, "Chapter 1", new List<string>
{
    "First paragraph of chapter 1.", 
    "Second paragraph with more text."
});

builder.AddChapter(2, "Chapter 2", new List<string>
{
    "Chapter 2 begins here.",
    "More content for chapter 2."
});

// Build and save
var writer = await builder.BuildAsync();
await writer.SaveToFileAsync("mybook.epub");

Creating an FB2 Book

// Create a new FB2 builder
var builder = FB2Builder.Create("My FB2 Book", "en")
    .WithAuthor("Author Name");

// Add cover
using (var coverStream = File.OpenRead("cover.jpg"))
{
    builder.WithCover(coverStream, "cover.jpg", "image/jpeg");
}

// Add chapters
builder.AddChapter(1, "Chapter 1", new[] { "Content for chapter 1" });
builder.AddChapter(2, "Chapter 2", new[] { "Content for chapter 2" });

// Build and save
var writer = await builder.BuildAsync();
await writer.SaveToFileAsync("mybook.fb2");

Using the Book Factory (Format-Agnostic)

// Create a book in any format with a simple interface
var format = BookFormat.Epub; // or BookFormat.FB2
IBookBuilder builder = BookFactory.CreateBuilder(format, "Book Title", "en");

// Use the fluent interface to configure the book
builder.WithAuthor("Author Name")
       .AddChapter(1, "Chapter", new[] { "Content" });

// Build and save
var writer = await builder.BuildAsync();
await writer.SaveAsStreamAsync(); // Get as stream
// or
await writer.SaveToFileAsync($"book.{format.ToString().ToLower()}");

Setting Up Logging

using Microsoft.Extensions.Logging;
using MyBook.Writer.Core.Services;

// Create a logger factory
using var loggerFactory = LoggerFactory.Create(builder =>
{
    builder
        .AddFilter("MyBook.Writer", LogLevel.Debug) // Set minimum level
        .AddConsole() // Log to console
        .AddDebug();  // Log to debug output
});

// Configure the book writer library to use our logger factory
loggerFactory.ConfigureBookWriter();

Detailed Logging Control

You can adjust the logging verbosity to get more detailed information:

// For normal operation
builder.AddFilter("MyBook.Writer", LogLevel.Information);

// For debugging
builder.AddFilter("MyBook.Writer", LogLevel.Debug);

// For detailed tracing (very verbose)
builder.AddFilter("MyBook.Writer", LogLevel.Trace);

NuGet Package

MyBook.Writer is available as a NuGet package:

To install the package, use one of the following methods:

Package Manager Console:

Install-Package MyBook.Writer

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 158 4/23/2025
1.0.0 94 4/11/2025