wai / flipbook
A package for displaying PDFs in a flipbook style
Requires
- php: >=7.1
- fpdf/fpdf: ^1.86
Requires (Dev)
- orchestra/testbench: 9.0
README
This package provides a flipbook style PDF viewer for Laravel projects. The PDF viewer is designed to be used out of the box without any implementation required, provided that the required public assets are published. However, the package supports customization of the PDF viewer by allowing for the built-in Blade view files to be published to your project. The PDF viewer can also be embedded directly into any Blade or Vue component to respond to trigger events as a popup dialog.
Installation
Install the package:
composer require wai/flipbook
Publish the required asset files:
php artisan flipbook:install
Optionally publish the Blade view files for customization:
php artisan vendor:publish --provider="Wai\FlipBook\FlipBookServiceProvider" --tag="views" --force
Scheduled Commands
This package supports optional caching of retrieved PDF files. To enable this feature, first publish the config file:
php artisan vendor:publish --provider="Wai\FlipBook\FlipBookServiceProvider" --tag="config"
The config file will be accessible in your project's config folder:
/config/flipbook.php
After enabling the cache config option, this package will run a scheduled command once a day to clean up stale PDFs that have not been viewed for several days. See the following link for running the scheduler:
https://laravel.com/docs/11.x/scheduling#running-the-scheduler
Usage
The necessary controller and routes are set up so that the PDF viewer can be accessed immediately once the package is installed. To access the PDF viewer simply pass the full URL of the PDF you wish to view to the following route:
/pdf?url=full-url-here
For example:
https://example.com/pdf?url=https://example.com/example
You may additionally pass a custom placeholder message for if the PDF cannot be retrieved from the designated URL:
https://example.com/pdf?url=https://example.com/example&text=Not%20found
Customization
Should you need to customize aspects of the PDF viewer, the published Blade view files can be found at the following path inside your project:
/resources/views/vendor/flipbook/
The published public assets (CSS, JS) can be found at:
/public/flipbook/
Local Development
Install composer dependencies:
composer install
Add the package to a local project's composer.json:
{
"scripts": { ... },
"repositories": [
{
"type": "path",
"url": "../path/to/local/git/repo/flipbook"
}
]
}
Install the package:
composer require wai/flipbook
Before committing changes, increment the version number specified in the package's composer.json. Additionally, create a new tag on Bitbucket matching the version number of the package.