mindtwo / base-flipbook
Framework-agnostic core of the mindtwo flipbook packages: turns a PDF into page images, page text and a manifest, and ships the accessible page-flip viewer.
Requires
- php: ^8.2
- ext-gd: *
- ext-json: *
Requires (Dev)
- laravel/pint: ^1.13
- pestphp/pest: ^2.34|^3.0|^4.0
- phpstan/phpstan: ^1.11|^2.0
- phpstan/phpstan-deprecation-rules: ^1.1|^2.0
Suggests
- ext-gd: WebP output needs GD with WebP support; otherwise JPEG is written.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-04 11:45:11 UTC
README
Framework-agnostic core of the mindtwo flipbook packages. It turns a PDF into page images, the
text of every page and a flipbook.json manifest, and ships an accessible page-flip viewer. A
self-hosted replacement for services like Yumpu or Issuu: no ads, no third-party trackers, the
content stays on the client's domain.
Platform packages:
mindtwo/statamic-flipbook— Statamic 5 and 6mindtwo/wordpress-flipbook— WordPress 6.5+- Any other PHP platform (TYPO3, Laravel, static sites): use this package directly, see below.
The viewer
- Double pages on desktop, single pages on phones, swipe on touch devices
- Floating toolbar with page input, side arrows, tooltips, reading progress, full screen
- Keyboard control, visible focus, live announcements for screen readers,
prefers-reduced-motion - Text version and download link rendered on the server (screen readers, search engines, no JavaScript, a viewer that fails to load)
- Optional PDF download with file size
- Neutral design, adapted through CSS custom properties; light and dark variant
- German and English labels, following the closest
langattribute - Deep links such as
#seite-12 - No external requests; StPageFlip 2.0.7 (MIT) is bundled, patched so its render loop stops when a
viewer is destroyed (see
bin/build-assets.sh)
Requirements
- PHP 8.2+ with GD (WebP support recommended; JPEG is written otherwise)
- poppler-utils on the server:
sudo apt install poppler-utils(Ubuntu/Forge),brew install poppler(macOS)
vendor/bin/flipbook check # poppler-utils found, image format: webp
Usage
Command line (any platform)
Until the package is published on Packagist, add the repository to the project's composer.json
first: "repositories": [{ "type": "vcs", "url": "https://github.com/mindtwo/base-flipbook" }].
composer require mindtwo/base-flipbook
vendor/bin/flipbook build magazine.pdf public/flipbooks/magazine --title="Magazine 02/26"
vendor/bin/flipbook assets public/vendor/flipbook
Run build again with the same directory for a new edition: the CLI converts next to it and
switches over once the new edition is complete, so the current one stays online and survives a
failed conversion. It refuses a directory that is not empty and holds no flipbook.
Then embed it in any template:
<link rel="stylesheet" href="/vendor/flipbook/flipbook.css"> <script src="/vendor/flipbook/flipbook.js" defer></script> <div class="mt-flipbook" data-flipbook-src="/flipbooks/magazine/flipbook.json" data-title="Magazine 02/26" data-pdf="/files/magazine.pdf" data-pdf-size="2.6 MB"></div>
Without server-rendered markup the viewer builds the header with the download link and the text
version from the data attributes and the manifest; data-heading-level="3" sets the level of its
page headings (2 to 6, default 2). For search engines and visitors without JavaScript, render them
with PHP instead (next section).
PHP
use Mindtwo\Flipbook\Builder; use Mindtwo\Flipbook\Html; use Mindtwo\Flipbook\Manifest; use Mindtwo\Flipbook\Options; $options = Options::fromArray([ 'widths' => [800, 1600], 'format' => 'webp', 'max_pages' => 400, 'process_timeout' => 120, // seconds per poppler call ]); // Convert (run this in a background job: about 1–2 s per page) $manifest = (new Builder($options))->build( '/tmp/upload.pdf', '/var/www/public/flipbooks/42/v1', 'Magazine 02/26', fn (int $done, int $total) => $status->progress($done, $total), ); // Render echo Html::assets('/vendor/flipbook'); echo Html::viewer($manifest, '/flipbooks/42/v1/flipbook.json', [ 'pdf_url' => '/files/magazine.pdf', 'pdf_size' => Html::fileSize(filesize('/tmp/upload.pdf')), 'heading_level' => 2, // page headings of the text version, 2 to 6 'lang' => 'de', ]);
Build into a new directory per conversion and switch over once build() returns, so visitors keep
seeing the previous edition while a new one is converted. build() refuses a target directory that
is not empty. If it fails, it removes what it wrote and throws ConversionFailed with a message
that is safe to show to editors; a directory that existed before is never deleted.
Content loaded later
The viewer starts flipbooks on DOMContentLoaded and then watches the page: flipbooks added or
re-rendered later (a Vue 2 app mounting on the page markup, Alpine, Livewire morphing, content loaded
with AJAX) start on their own, and viewers whose markup left the page are destroyed. For content
swapped in by a router (Turbo, Livewire wire:navigate, Swup, Barba), you can still call
MtFlipbook.destroy(container) before the old content is removed and MtFlipbook.init(container)
after the new content is in place, e.g. to pass options. init() with options also rebuilds a
flipbook that already runs, so it does not matter whether the viewer started it first. Options stay
with their flipbook, also when a framework re-renders its markup: a flipbook without an id gets
one from its position on the page, so it gets the same one again. Without an argument, both act on
the whole document.
Styling
.mt-flipbook { --mt-flipbook-accent: #005a9c; /* progress bar, focus ring */ --mt-flipbook-bg: #f4f4f5; /* stage background */ --mt-flipbook-controls-bg: #0b2545; /* floating toolbar */ --mt-flipbook-controls-text: #fff; --mt-flipbook-font: "Inter", sans-serif; --mt-flipbook-radius: 0; --mt-flipbook-max-height: 80vh; }
Add mt-flipbook--dark to the element for dark pages.
Accessibility
The viewer is built to WCAG 2.1 AA practice, but the quality of the text version depends on the
PDF. For full accessibility export the PDF as PDF/UA (tagged, with reading order and
alternative texts) and keep the download enabled. Manifest::$tagged tells whether a PDF is
tagged; the platform packages show it to editors.
Development
composer install composer check # pint --test, phpstan (level 8), pest bin/build-assets.sh # after changes in resources/src; commit resources/dist
The feature tests convert tests/fixtures/sample.pdf and are skipped without poppler-utils.
License
MIT, see LICENSE.md. The bundled StPageFlip is MIT-licensed as well (resources/dist/page-flip.LICENSE).