PHPackages                             tregor/epub - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tregor/epub

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tregor/epub
===========

description

1.0.3(2y ago)244proprietaryPHP

Since Oct 6Pushed 2y ago1 watchersCompare

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

READMEChangelog (3)DependenciesVersions (4)Used By (0)

EPub Generator
==============

[](#epub-generator)

[![GitHub stars](https://camo.githubusercontent.com/158565f7c9f2859820c443ef84a25ee8d77f94791a0e282f0b21e5b247419de4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f747265676f722f657075623f7374796c653d666c61742d737175617265)](https://github.com/tregor/epub/stargazers)[![Last Commit](https://camo.githubusercontent.com/3ba94513ae002428bf8db6fe204a67185631cd17a55156cfb20d547c8cf3d68e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f747265676f722f657075623f7374796c653d666c61742d737175617265)](https://github.com/tregor/epub)[![GitHub forks](https://camo.githubusercontent.com/64ea41843f157494b0dbe6a739e298b03e0c006ac261afc59d43d12ca1ed6185/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f747265676f722f657075623f7374796c653d666c61742d737175617265)](https://github.com/tregor/epub/network)[![GitHub license](https://camo.githubusercontent.com/16be215e28b9371acc073cd3c1e89d91c727aafd2cfe3de7f74be8f6730d749d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f747265676f722f657075623f7374796c653d666c61742d737175617265)](LICENSE)

The EPub Generator is a powerful PHP library for creating EPub books. It provides a comprehensive set of features and an intuitive API to generate EPub files with ease. Whether you're a writer, publisher, or developer, this library will simplify the process of creating EPub books and help you deliver high-quality content to your readers.

Features
--------

[](#features)

- Create EPub books from scratch
- Set book metadata such as title, author, and language
- Add chapters with custom titles, content, and order
- Remove, update, and rearrange chapters
- Export EPub books to standard EPub files
- Parse EPub files and retrieve book information

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- XMLWriter extension
- Zip extension

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require tregor/epub
```

Usage
-----

[](#usage)

### Creating a New EPub Book

[](#creating-a-new-epub-book)

To create a new EPub book, you need to instantiate the `EPubBook` class and provide the book's title:

```
use tregor\epub\EPubBook;

$book = new EPubBook('My First Book');
```

### Parsing an Existing EPub Book

[](#parsing-an-existing-epub-book)

You can also parse an existing EPub book and retrieve its information. To do this, use the `open` method:

```
$book = EPubBook::open('existing_book.epub');
```

### Setting Book Metadata

[](#setting-book-metadata)

You can set the author and language of the book using the `setAuthor` and `setLanguage` methods:

```
$book->setAuthor('John Doe');
$book->setLanguage('en');
```

### Adding Chapters

[](#adding-chapters)

You can add chapters to the book using the `addChapter` method. Each chapter requires a title, content, and order:

```
$book->addChapter('Chapter 1', 'This is the first chapter.', 1);
$book->addChapter('Chapter 2', 'This is the second chapter.', 2);
```

### Rearranging Chapters

[](#rearranging-chapters)

You can add a new chapter after an existing chapter by specifying the order of the existing chapter, the title and content of the new chapter, and the new order:

```
$book->addChapterAfter(1, 'Chapter 2', 'This is the new Chapter 2.', 2);
```

### Removing Chapters

[](#removing-chapters)

To remove a chapter from the book, specify its order:

```
$book->removeChapter(2);
```

### Updating Chapters

[](#updating-chapters)

You can update the content of a chapter by specifying its order and providing the new content:

```
$book->setChapterContent(1, 'This is the updated content of Chapter 1.');
```

### Exporting the EPub Book

[](#exporting-the-epub-book)

Once you have added all the chapters, you can export the EPub book to a file using the `export` method:

```
$book->export('my_first_book.epub');
```

Available Methods
-----------------

[](#available-methods)

Here are the available methods provided by the `EPubBook` class:

- `__construct($title)`: Creates a new `EPubBook` object with the specified title.
- `addChapter($title, $content, $order)`: Adds a new chapter to the book with the specified title, content, and order.
- `removeChapter($order)`: Removes a chapter from the book with the specified order.
- `addChapterAfter($order, $title, $content, $newOrder)`: Adds a new chapter after an existing chapter with the specified order, title, content, and new order.
- `getChapterContent($order)`: Retrieves the content of a chapter with the specified order.
- `setChapterContent($order, $content)`: Updates the content of a chapter with the specified order.
- `export($filename)`: Exports the book to an EPub file with the specified filename.
- `getTitle()`: Retrieves the title of the book.
- `setTitle($title)`: Sets the title of the book.
- `getAuthor()`: Retrieves the author of the book.
- `setAuthor($author)`: Sets the author of the book.
- `getLanguage()`: Retrieves the language of the book.
- `setLanguage($language)`: Sets the language of the book.

TODO
----

[](#todo)

Here is a list of features that we plan to implement in future releases:

- Support for adding a table of contents
- Support for adding a cover image
- Support for adding additional metadata
- Improved error handling and exception handling

License
-------

[](#license)

The EPub Generator is proprietary software. See the [license file](LICENSE) for more information.

Contributing
------------

[](#contributing)

Contributions are welcome! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request.

Credits
-------

[](#credits)

The EPub Generator library is developed and maintained by [tregor](https://github.com/tregor).

Keywords
--------

[](#keywords)

EPub, EPub Generator, PHP, Library, EPub Book, EPub Format, EPub Files, EPub Creation, EPub Parser, EPub Writer, EPub Library, EPub PHP Library, EPub Generator PHP, EPub Generator Library, EPub Generator PHP Library, EPub Generator Example, EPub Generator Usage, EPub Generator Documentation, EPub Generator Tutorial, EPub Generator Guide, EPub Generator Features, EPub Generator Requirements, EPub Generator Installation, EPub Generator API, EPub Generator Methods, EPub Generator TODO, EPub Generator License, EPub Generator Contributing, EPub Generator Credits

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~1 days

Total

3

Last Release

952d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4f9c79ece6c5db08deb64eb90577aa98570ee03e8e54e5404597b25a20127a2c?d=identicon)[tregor](/maintainers/tregor)

---

Top Contributors

[![tregor](https://avatars.githubusercontent.com/u/4541631?v=4)](https://github.com/tregor "tregor (15 commits)")

### Embed Badge

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

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

PHPackages © 2026

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