Skip to content

Commit

Permalink
Add config to choose pdf package to use (dompdf, snappy)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy-JS committed Aug 25, 2021
1 parent fe9dd53 commit d6fd6a8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion config/report-generator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

return [
'flush' => false
'flush' => false,
'pdfLibrary' => 'snappy' // snappy, dompdf
];
14 changes: 13 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@ If you are running Laravel > 5.5 that's all you need to do. If you are using Lar
'ExcelReport' => Jimmyjs\ReportGenerator\Facades\ExcelReportFacade::class,
'CSVReport' => Jimmyjs\ReportGenerator\Facades\CSVReportFacade::class,

For more better speed on generating pdf report, I recommend you to use laravel snappy package. To using laravel snappy, you should install `wkhtmltopdf` to work with this package [(Jump to wkhtmltopdf installation)](#wkhtmltopdf-installation)
**Optionally**, You can publish the config file (then it will be available in `config/report-generator.php`)

php artisan vendor:publish --provider="Jimmyjs\ReportGenerator\ServiceProvider"

If you want to generate a pdf report, please install either dompdf / snappy pdf.
This package will automatically use snappy pdf. If you want to use dompdf then please change `config/report-generator.php`:

return [
'flush' => false,
'pdfLibrary' => 'dompdf'
];

For better speed on generating pdf report, I recommend you to use laravel snappy package. To using laravel snappy, you should install `wkhtmltopdf` to work with this package [(Jump to wkhtmltopdf installation)](#wkhtmltopdf-installation)

### Example Display PDF Code
```php
Expand Down
6 changes: 4 additions & 2 deletions src/ReportMedia/PdfReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Jimmyjs\ReportGenerator\ReportMedia;

use Config;
use Jimmyjs\ReportGenerator\ReportGenerator;

class PdfReport extends ReportGenerator
Expand All @@ -28,12 +29,13 @@ public function make()
$html = \View::make('laravel-report-generator::general-pdf-template', compact('headers', 'columns', 'editColumns', 'showTotalColumns', 'styles', 'query', 'limit', 'groupByArr', 'orientation', 'showHeader', 'showMeta', 'applyFlush', 'showNumColumn'))->render();
}

try {
$pdfLibrary = Config::get('report-generator.pdfLibrary', 'snappy');
if ($pdfLibrary === 'snappy') {
$pdf = \App::make('snappy.pdf.wrapper');
$pdf->setOption('footer-font-size', 10);
$pdf->setOption('footer-left', 'Page [page] of [topage]');
$pdf->setOption('footer-right', 'Date Printed: ' . date('d M Y H:i:s'));
} catch (\ReflectionException $e) {
} else if ($pdfLibrary === 'dompdf') {
try {
$pdf = \App::make('dompdf.wrapper');
} catch (\ReflectionException $e) {
Expand Down

0 comments on commit d6fd6a8

Please sign in to comment.