Download the PHP package adrorocker/epub-builder without Composer

On this page you can find all versions of the php package adrorocker/epub-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package epub-builder

adrorocker/epub-builder

tests

Convert Tiptap JSON documents into valid EPUB 3.3 files. Framework-agnostic, zero runtime dependencies, with an injectable renderer interface so you can plug in your own Tiptap-to-XHTML logic.


Installation

Requirements: PHP 8.1+, ext-zip, ext-dom.


Quick start

That's a complete, valid EPUB. Open in any reader.


Metadata

All metadata is set through a fluent builder. Title, language, and at least one chapter are required; everything else is optional.

MARC relator codes

contributor() takes an optional second argument — a MARC relator code describing the contributor's role. Common ones:

Code Role
trl Translator
edt Editor
ill Illustrator
pht Photographer
aui Introduction
aft Afterword
fwd Foreword
cmp Compiled by
nrt Narrated by
oth Other (default)

These codes are emitted into the OPF and translated to readable labels ("Translated by", "Edited by", …) on the auto-generated cover page.


Chapters

Each call to addChapter(string $title, array $tiptapJson) adds one chapter:


Cover page

When you set a cover image, the library auto-generates a title page (OEBPS/chapters/cover.xhtml) showing:

  1. The cover image, full-bleed
  2. The book title (large, centered)
  3. Authors ("by Robert Frost & Jane Doe")
  4. Contributors with role labels ("Translated by Constance Garnett")
  5. Publisher
  6. Year
  7. Rights / copyright line
  8. Description (justified, smaller text)

This is rendered XHTML, so it shows up the same in every reader — even readers that don't surface OPF metadata in their library/info UIs.

The cover is automatically:


Output

build() returns an EpubOutput value object:

If you don't pass a path to build(), it writes to sys_get_temp_dir() with a random name.

Streaming without keeping a file

When you don't want a file at all — e.g. you're piping the EPUB straight into an HTTP response or an S3 upload — use buildToStream() or buildToString(). They use a temp file internally and delete it once the bytes are out.

Laravel

Or stream without staging the file in your storage directory:

Symfony

Streaming variant via StreamedResponse:


Custom Tiptap nodes

The default renderer ships handlers for the standard Tiptap node and mark set:

Nodes: doc, paragraph, heading, blockquote, codeBlock, bulletList, orderedList, listItem, horizontalRule, hardBreak, image, table, tableRow, tableCell, tableHeader, text, pageBreak

Marks: bold, italic, underline, strike, code, link, highlight, subscript, superscript

Unknown nodes are silently dropped (so editors emitting custom node types like unsplashImage, callout, embed don't crash builds). To opt in to rendering a custom node, write a NodeHandlerInterface and register it:

Now {"type": "callout", "attrs": {"type": "warning"}, "content": [...]} renders to <aside class="callout callout--warning">…</aside>.

Custom node that needs to embed images

If your custom node has remote or local image references, register them with the AssetManager so they're embedded in the EPUB:

A complete working example is in examples/UnsplashImageHandler.php.

Overriding a built-in node

override() replaces a default handler:

Custom marks

Same pattern via MarkHandlerInterface:


Custom renderer (full replacement)

If you'd rather not use the default renderer at all — for example, you have an existing Tiptap-to-HTML pipeline you want to wrap — implement ContentRendererInterface:

You'd typically use this to wrap a third-party Tiptap PHP renderer like ueberdosis/tiptap-php. The default renderer remains an option you can fall back to.


Styling

A clean default stylesheet is embedded automatically. To customize:


Navigation features

The library auto-generates three EPUB nav structures (you don't have to think about any of them):

Plus the legacy formats for older readers:


Verification

The library passes EPUBCheck 5.x (the W3C reference validator) with 0 errors / 0 warnings on every build. To verify your output:

Expected output:


Spec references

The library follows the W3C EPUB 3.3 Recommendation:

Plus selected EPUB 2 features for legacy-reader compatibility (NCX, <guide>, <meta name="cover">).


API reference

EpubBuilder

Method Description
EpubBuilder::create(): static Entry point — start a new builder.
setMetadata(callable $cb): static $cb(BookMetadata $m) — configure metadata.
addChapter(string $title, array $tiptapJson): static Add a chapter.
setRenderer(ContentRendererInterface): static Replace the default Tiptap renderer entirely.
getRenderer(): ContentRendererInterface Get the current renderer (used to register custom nodes/marks before adding chapters).
setStylesheet(string $path): static Use a custom CSS file in place of the default.
addCss(string $css): static Append CSS rules to the default (or custom) stylesheet.
disableAutoPageList(): static Opt out of one-page-per-chapter page-list entries.
disableNcx(): static Opt out of the legacy EPUB 2 NCX fallback.
assetManager(): AssetManager Internal asset manager (for custom node handlers that embed images/fonts).
tocBuilder(): TocBuilder Internal TOC builder (for custom heading-like nodes).
pageListBuilder(): PageListBuilder Internal page-list builder (for custom page-break nodes).
metadata(): BookMetadata Direct access to the metadata object.
build(?string $path = null): EpubOutput Validate, render, and write the EPUB.
buildToStream($resource, int $chunkSize = 8192): int Build and copy bytes into a writable stream resource; deletes the temp file afterwards. Returns bytes written.
buildToString(): string Build and return the EPUB as a binary string; deletes the temp file afterwards.

BookMetadata

All setters return static for chaining.

Method EPUB field
title(string) <dc:title> (required)
language(string) <dc:language> (required, BCP 47)
author(string) <dc:creator> — call multiple times for multiple authors
contributor(string $name, string $role = 'oth') <dc:contributor> with MARC relator role
subject(string) <dc:subject> — call multiple times for multiple tags
publisher(string) <dc:publisher>
description(string) <dc:description>
rights(string) <dc:rights>
isbn(string) <dc:identifier> with urn:isbn: prefix
coverImage(string $path) Triggers cover-page generation; image is embedded
direction(string) 'ltr' (default) or 'rtl'
series(string $name, ?int $position) EPUB 3 collection metadata
identifier(string) Override the auto-generated UUIDv4
modified(\DateTimeImmutable) Override the auto-generated modification time

EpubOutput

Method Description
getPath(): string Path on disk where the EPUB was written.
getSize(): int File size in bytes.
getContents(): string Raw EPUB bytes.
download(string $filename = 'book.epub'): never Stream as HTTP download (calls exit).
streamTo($resource, int $chunkSize = 8192): int Copy the EPUB into any writable stream resource in chunks. Returns bytes written.
chunks(int $chunkSize = 8192): \Generator Yield the EPUB body as a generator of byte chunks.
delete(): void Remove the file.

Architecture overview

The package is intentionally small and composable: replace any layer by passing a different implementation, or extend behavior by registering handlers in the registries.


License

MIT.


All versions of epub-builder with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-zip Version *
ext-dom Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package adrorocker/epub-builder contains the following files

Loading the files please wait ...