HTML → EPUB icon

HTML → EPUB

Convert HTML (binary or string) to EPUB file

Overview

This node converts HTML content into an EPUB ebook file. It supports input HTML either as binary data or as a string within JSON, and can optionally include a cover image provided as binary data or via URL. The node processes the HTML to split it into chapters based on <h1 class="chapter"> tags, applies styling, and packages everything into a valid EPUB format.

Common scenarios:

  • Automating the creation of ebooks from web-scraped or dynamically generated HTML content.
  • Converting blog posts, articles, or documentation stored in HTML into portable EPUB files for offline reading.
  • Generating customized ebooks with metadata like title, author, language, and cover images.

Practical example:

  • You have a collection of HTML chapters stored as binary files or JSON strings in your workflow. Using this node, you convert them into a single EPUB file with proper chapters and optional cover image, ready for distribution or personal use.

Properties

Name Meaning
Input Mode Source of the input HTML. Options: Binary (HTML), String (HTML)
Binary Property Name Name of the binary property containing the HTML (used if Input Mode is binary)
JSON Property Name with HTML JSON key containing the raw HTML string (used if Input Mode is string)
Cover Image Mode How to provide the cover image. Options: None, Binary, URL
Cover Image Binary Property Name Binary property containing the cover image (used if Cover Image Mode is binary)
Cover Image URL URL of the cover image (used if Cover Image Mode is url)
Title Title to set in the EPUB metadata (optional)
Author Author name to set in the EPUB metadata (default: "Unknown")
Language Language code of the book (default: "en")
EPUB File Name Name of the output EPUB file (default: "book.epub")
Output Binary Property Name Name of the binary property where the resulting EPUB file will be written (default: "data")

Output

The node outputs the generated EPUB file as binary data under the specified output binary property name (default "data"). The binary data represents a fully structured EPUB archive including:

  • XHTML chapter files split by detected chapters (<h1 class="chapter">).
  • CSS styling for tables inside chapters.
  • Metadata files (content.opf, toc.ncx, container XML).
  • Optional cover image and cover page.
  • A unique UUID for the book.

Additionally, the node adds metadata fields to the JSON output for each item:

  • meta.uuid: Unique identifier of the EPUB.
  • meta.title: Title of the EPUB.
  • meta.author: Author of the EPUB.
  • meta.language: Language code.
  • meta.chapters: Number of chapters included.
  • meta.coverImage: Boolean indicating if a cover image was included.

If a cover image is provided, it is embedded in the EPUB either as a binary file or linked by URL.


Dependencies

  • Requires no external API keys or services.
  • Uses internal helpers for:
    • Accessing binary data buffers.
    • HTTP requests (for fetching cover image by URL).
    • Preparing binary data for output.
  • Uses these npm packages bundled with the node:
    • cheerio for HTML parsing and manipulation.
    • zlib for compression inside the EPUB archive.

No special environment variables or n8n credential types are required beyond standard HTTP request capabilities if using cover image URL mode.


Troubleshooting

  • Error: The JSON property 'X' must contain a non-empty HTML string.
    This occurs if the input mode is set to string but the specified JSON property does not exist or is empty.
    Resolution: Ensure the input JSON contains a valid non-empty HTML string at the configured property name.

  • Cover image not included or invalid:
    If cover image mode is binary but the specified binary property is missing or empty, the cover will be omitted silently. Similarly, if the URL is invalid or unreachable, no cover image will be added.
    Resolution: Verify the binary property or URL is correct and accessible.

  • Output EPUB file is corrupted or unreadable:
    Could happen if the input HTML is malformed or extremely large.
    Resolution: Validate and clean input HTML before conversion. Check logs for any errors during processing.

  • Node fails on some items but continues on others:
    If "Continue On Fail" is enabled, errors per item are captured in the output JSON under an error field.
    Resolution: Inspect error details in output to identify problematic inputs.


Links and References


This node provides a straightforward way to automate EPUB generation from HTML content within n8n workflows, supporting flexible input modes and cover image options.

Discussion