A Laravel implementation of DearFlip PDF Flipbook viewer.
DearFlip is a powerful PDF Flipbook solution that offers a realistic book-like experience for viewing PDF documents on the web. This repository demonstrates how to integrate DearFlip with a Laravel application.
- PHP 8.1+
- Laravel 10.x
- jQuery (included with DearFlip)
Purchase and download DearFlip from official website.
Extract the DearFlip package and copy the following directories to your Laravel public folder:
cp -r dflip/ /path/to/your/laravel/public/
Your directory structure should look like:
public/
├── dflip/
│ ├── css/
│ ├── js/
│ ├── sound/
│ └── images/
Place your PDF files in the public directory:
public/
├── pdf/
│ └── your-document.pdf
In your Blade template (e.g., welcome.blade.php), include the required CSS and JavaScript files:
<!-- DearFlip assets -->
<link rel="stylesheet" href="/dflip/css/dflip.min.css">
<script src="/dflip/js/libs/jquery.min.js"></script>
<script src="/dflip/js/dflip.js"></script>
Add a container element where the PDF flipbook will be rendered:
<div data-option="dflipOptions" class="df-element"></div>
Set the DearFlip configuration in your controller and pass it to the view:
// In your route or controller
$dflipOptions = [
'source' => '/pdf/your-document.pdf'
];
return view('welcome', compact('dflipOptions'));
In your Blade template, initialize DearFlip with these options:
<script>
window.dflipLocation = "/dflip/";
window.dflipOptions = @json($dflipOptions)
</script>
DearFlip offers many customization options. Here are some commonly used ones:
$dflipOptions = [
'source' => '/pdf/your-document.pdf',
'height' => 800, // Height in pixels, or 'auto'
'duration' => 800, // Page turn animation duration
'backgroundColor' => "#FFFFFF", // Background color
'autoEnableOutline' => true, // Auto show document outline
'autoEnableThumbnail' => true, // Auto show thumbnails
'enableDownload' => true, // Enable PDF download
'enableSound' => true, // Enable page flip sound
'webgl' => true, // Use WebGL rendering
'hard' => 'all', // Hard pages (none, cover, all)
'openPage' => 1, // Initial page to open
'pageMode' => 2, // 1=single, 2=double
'singlePageMode' => 1, // 1=zoom, 2=booklet
];
You can set callbacks for various events:
$dflipOptions = [
'source' => '/pdf/your-document.pdf',
'onReady' => 'function(app) { console.log("DearFlip is ready!"); }',
'onPageChanged' => 'function(app) { console.log("Page changed to: " + app.currentPageNumber); }',
'onCreate' => 'function(app) { console.log("DearFlip created"); }',
];
To have multiple PDF viewers on a single page:
<div id="pdf1" class="df-element"></div>
<div id="pdf2" class="df-element"></div>
<script>
$('#pdf1').flipBook('/pdf/document1.pdf', {
height: 600,
backgroundColor: "#FFC0CB"
});
$('#pdf2').flipBook('/pdf/document2.pdf', {
height: 600,
backgroundColor: "#ADD8E6"
});
</script>
DearFlip is mobile-friendly. For best results on smaller screens, consider adjusting some settings:
$dflipOptions = [
'source' => '/pdf/your-document.pdf',
'mobileViewMode' => 1, // Force single page mode on mobile
];
- Check if the PDF path is correct
- Ensure the PDF file is accessible (proper permissions)
- Verify that all DearFlip assets are correctly loaded
Check the browser's console for any JavaScript errors, which may indicate:
- Missing DearFlip files
- jQuery conflicts
- PDF loading issues
- Official Documentation: http://js.dearflip.com/docs
- Support: https://dearflip.com/support
DearFlip requires a license purchase from https://dearflip.com.
This Laravel implementation example is for demonstration purposes.