PHPackages                             tekkcraft/epub-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. tekkcraft/epub-generator

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

tekkcraft/epub-generator
========================

Generate EPUB files

214PHP

Since May 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/TekkCraft/epub-generator)[ Packagist](https://packagist.org/packages/tekkcraft/epub-generator)[ RSS](/packages/tekkcraft-epub-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

EPUB generator
==============

[](#epub-generator)

A simple library to generate EPUB files.

Usage
-----

[](#usage)

```
$coverImage = new \Tekkcraft\EpubGenerator\EpubAsset('path/to/image-folder', 'cover.png', 'image/png');

$generator = new \Tekkcraft\EpubGenerator\EpubDocument('book', 'TekkCraft', 'unique-book-name', '/path/to/storage-directory', $coverImage);

$css = new EpubAsset(
    'path/to/css-folder',
    'epub.css',
    'text/css',
);
$generator->addCss($css);

$sectionOne = new \Tekkcraft\EpubGenerator\EpubSection(
    'section1',
    'Section 1',
    'Chapter 1This is the content of Chapter 1.',
);
$generator->addSection($sectionOne);

$image = new \Tekkcraft\EpubGenerator\EpubAsset('path/to/image-folder', 'image.png', 'image/png');
$generator->addImage($image);

$sectionTwo = new \Tekkcraft\EpubGenerator\EpubSection(
    'section2',
    'Section 2',
    'Chapter 2This is the content of Chapter 2.',
);
$generator->addSection($sectionTwo);

$epubFile = $generator->generateEpub();
```

This would create a new EPUB file named `book.epub` in the directory `/path/to/storage-directory`. The `$epubFile` contains the file name of the generated EPUB.

All images are saved in the `img` folder and can be accessed using `img/image-name.png`.
All CSS assets are saved in the `css` folder and can be accessed using `css/file-name.css`.

All sections will be saved into the `xhtml` directory, meaning if you want to reference an image from one of your sections, you will need to call it in your HTML using `../img/my-image.png`.

Required headers for download
-----------------------------

[](#required-headers-for-download)

If you want to provide your EPUB file as a download, add these headers:

```
header('Content-Type: application/epub+zip');
header(sprintf('Content-Disposition: attachment; filename="%s.epub"', 'my-ebook'));
header(sprintf('Content-Length: %s', strlen($epubFile)));
```

Validating an EPUB file
-----------------------

[](#validating-an-epub-file)

To validate an epub file, you can use the [epubcheck tool](https://github.com/w3c/epubcheck) provided by w3c.
I did not include this in my repository as it is a .jar file and therefore needs Java to run. In addition to that, you will probably have to use PHP's exec() function to call it, which is generally unsafe.

(It is, however downloaded when running the test suite, as this should not happen on a production system)

Testing
-------

[](#testing)

In order to run the PHPUnit test suite you will need to have java installed on your system in order to use the `epubcheck.jar`. The `epubcheck.jar` will be downloaded from  and saved into the `sys_get_temp_dir()` on first test execution.

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b050d749c4ab8bed88c2028cfdff424468e0c14a711962cb27117dafbb9e454d?d=identicon)[TekkCraft](/maintainers/TekkCraft)

---

Top Contributors

[![TekkCraft](https://avatars.githubusercontent.com/u/21214298?v=4)](https://github.com/TekkCraft "TekkCraft (31 commits)")

### Embed Badge

![Health badge](/badges/tekkcraft-epub-generator/health.svg)

```
[![Health](https://phpackages.com/badges/tekkcraft-epub-generator/health.svg)](https://phpackages.com/packages/tekkcraft-epub-generator)
```

###  Alternatives

[phpoffice/phpspreadsheet

PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine

13.9k293.5M1.2k](/packages/phpoffice-phpspreadsheet)[spatie/browsershot

Convert a webpage to an image or pdf using headless Chrome

5.2k32.1M100](/packages/spatie-browsershot)[smalot/pdfparser

Pdf parser library. Can read and extract information from pdf file.

2.7k34.5M215](/packages/smalot-pdfparser)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[openspout/openspout

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.1k57.6M128](/packages/openspout-openspout)[keboola/csv

Keboola CSV reader and writer

1451.8M21](/packages/keboola-csv)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
