PHPackages                             andileco/php-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. andileco/php-epub

ActiveLibrary

andileco/php-epub
=================

A modern PHP library for creating ePub 3 ebooks. Zero dependencies, full ePub 3.0.1 compliance, accessibility support, SVG and MathML embedding.

1.0.0(1mo ago)369↓50%MITPHPPHP ^8.2

Since Jul 11Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/andileco/php-epub)[ Packagist](https://packagist.org/packages/andileco/php-epub)[ RSS](/packages/andileco-php-epub/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

php-epub
========

[](#php-epub)

A modern PHP library for creating ePub 3 ebooks. Zero dependencies, full ePub 3.0.1 compliance, ePub 2 NCX fallback, accessibility metadata, SVG and MathML support.

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

[](#requirements)

- PHP 8.2+
- ext-zip
- ext-dom
- ext-libxml

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

[](#installation)

```
composer require andileco/php-epub
```

Quick Start
-----------

[](#quick-start)

```
use PhpEpub\Epub;
use PhpEpub\Metadata;
use PhpEpub\Chapter;
use PhpEpub\Resource;
use PhpEpub\Semantic;

$epub = Epub::create()
    ->metadata(
        Metadata::create('My Book')
            ->authors(['Jane Doe'])
            ->isbn('978-1234567890')
            ->publisher('Example Press')
    )
    ->stylesheet(Resource::fromFile('styles.css'))
    ->chapter(
        Chapter::create('Introduction', 'IntroductionWelcome.')
            ->semantic(Semantic::INTRODUCTION)
    )
    ->chapter(
        Chapter::create('Chapter 1', 'Getting StartedContent here...')
            ->semantic(Semantic::CHAPTER)
            ->subChapter(
                Chapter::create('Prerequisites', 'PrerequisitesYou need...')
            )
    )
    ->save('my-book.epub');
```

Features
--------

[](#features)

### Fluent Builder API

[](#fluent-builder-api)

All builder methods return new instances (immutable), so you can chain them:

```
$epub = Epub::create()
    ->metadata($meta)
    ->stylesheet($css)
    ->chapter($ch1)
    ->chapter($ch2);
```

### ePub 3 Semantic Types

[](#epub-3-semantic-types)

Tag chapters with semantic meaning from the EPUB 3 Structural Semantics Vocabulary:

```
->chapter(Chapter::create('Preface', $html)->semantic(Semantic::PREFACE))
->chapter(Chapter::create('Chapter 1', $html)->semantic(Semantic::CHAPTER))
->chapter(Chapter::create('Glossary', $html)->semantic(Semantic::GLOSSARY))
```

This adds `epub:type` attributes to the XHTML and generates a landmarks navigation.

### Nested Chapters

[](#nested-chapters)

Create hierarchical table of contents:

```
->chapter(
    Chapter::create('Part One', 'Intro to part one.')
        ->subChapter(Chapter::create('Section 1.1', 'Details.'))
        ->subChapter(Chapter::create('Section 1.2', 'More details.'))
)
```

### SVG Support

[](#svg-support)

SVG is an ePub 3 core media type. Include inline SVG for charts, diagrams, and illustrations:

```
$html = 'Here is a chart:

';

->chapter(Chapter::create('Data Visualization', $html))
```

The library automatically detects SVG content and sets the required `properties="svg"` in the OPF manifest.

### MathML Support

[](#mathml-support)

Include mathematical equations using MathML:

```
$html = 'The quadratic formula:

  x=

    -b±b2-4ac
    2a

';

->chapter(Chapter::create('Equations', $html))
```

### Fixed Layout

[](#fixed-layout)

Create pixel-perfect pages for comics, cookbooks, data dashboards, and children's books:

```
// Entire book as fixed layout
Epub::create()
    ->metadata(
        Metadata::create('My Cookbook')
            ->fixedLayout(1024, 768)  // width, height in CSS pixels
    )
    ->chapter(Chapter::create('Recipe 1', $htmlWithAbsolutePositioning))
    ->save('cookbook.epub');
```

Presets are available for common dimensions:

```
use PhpEpub\Viewport;

Viewport::tablet()          // 1024 × 768
Viewport::tabletPortrait()  // 768 × 1024
Viewport::letter()          // 816 × 1056
Viewport::a4()              // 794 × 1123
```

For full control over spread and orientation:

```
use PhpEpub\Layout;
use PhpEpub\Spread;
use PhpEpub\Viewport;

Metadata::create('My Comic')
    ->layout(Layout::PRE_PAGINATED)
    ->viewport(Viewport::tablet())
    ->spread(Spread::LANDSCAPE)   // Two-page spread in landscape
    ->orientation('landscape')     // Prefer landscape reading
```

### Mixed Layout

[](#mixed-layout)

Combine reflowable and fixed-layout pages in a single book. Useful for a reflowable book with occasional full-page charts or illustrations:

```
Epub::create()
    ->metadata(Metadata::create('Annual Report'))  // Reflowable by default
    ->chapter(Chapter::create('Introduction', 'Text content...'))
    ->chapter(
        Chapter::create('Q4 Dashboard', $svgChartHtml)
            ->layout(Layout::PRE_PAGINATED)
            ->viewport(new Viewport(1024, 768))
    )
    ->chapter(Chapter::create('Conclusion', 'More text...'))
    ->save('report.epub');
```

### Accessibility

[](#accessibility)

Include EPUB Accessibility and schema.org metadata:

```
Metadata::create('My Book')
    ->accessibility(
        accessMode: ['textual', 'visual'],
        accessModeSufficient: ['textual'],
        features: ['structuralNavigation', 'tableOfContents', 'alternativeText'],
        summary: 'This book includes structured headings and alt text for all images.',
        hazards: ['none'],
        conformsTo: 'http://www.idpf.org/epub/a11y/accessibility-20170105.html#wcag-aa',
    )
```

### Resources

[](#resources)

Embed images, fonts, and other files:

```
// From file
->resource(Resource::fromFile('/path/to/image.jpg', 'images/photo.jpg'))

// From string
->resource(Resource::fromString($svgData, 'images/chart.svg'))
```

### Cover Image

[](#cover-image)

```
->coverImage(Resource::fromFile('/path/to/cover.jpg'))
```

### Output Options

[](#output-options)

```
// Save to file
$epub->save('/path/to/book.epub');

// Get raw binary data
$data = $epub->build();

// Write to stream
$epub->writeTo($stream);
```

Architecture
------------

[](#architecture)

The library is organized into a public API and internal implementation:

- **Public:** `Epub`, `Metadata`, `Chapter`, `Resource`, `Semantic`, `Accessibility`
- **Internal:** `Packager`, `OpfBuilder`, `NavBuilder`, `NcxBuilder`, `XhtmlBuilder`, `ContainerBuilder`, `MimeTypes`

Internal classes handle the ePub specification details (OPF manifest, ZIP packaging, XHTML wrapping) and should not be used directly.

License
-------

[](#license)

MIT

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance90

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75% 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

Unknown

Total

1

Last Release

50d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2522839?v=4)[andileco](/maintainers/andileco)[@andileco](https://github.com/andileco)

---

Top Contributors

[![andileco](https://avatars.githubusercontent.com/u/2522839?v=4)](https://github.com/andileco "andileco (3 commits)")[![claude](https://avatars.githubusercontent.com/u/81847?v=4)](https://github.com/claude "claude (1 commits)")

---

Tags

svgaccessibilitypublishingebookepubepub3

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[blade-ui-kit/blade-icons

A package to easily make use of icons in your Laravel Blade views.

2.5k49.9M482](/packages/blade-ui-kit-blade-icons)[picqer/php-barcode-generator

An easy to use, non-bloated, barcode generator in PHP. Creates SVG, PNG, JPG and HTML images from the most used 1D barcode standards.

1.8k30.6M140](/packages/picqer-php-barcode-generator)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

55516.9M73](/packages/meyfa-php-svg)[easybook/easybook

Book publishing application

75911.6k](/packages/easybook-easybook)[kiwilan/php-ebook

PHP package to read metadata and extract covers from eBooks, comics and audiobooks.

3819.5k4](/packages/kiwilan-php-ebook)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

568.3M169](/packages/symfony-ux-icons)

PHPackages © 2026

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