From 46db6537d653433aaafe50b5e058fa0285ffd05a Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 1 Aug 2018 23:29:16 +1000 Subject: [PATCH] Invoice PDF rendering --- app/Http/Controllers/UserHomeController.php | 6 + composer.json | 4 +- composer.lock | 375 ++++++++---------- config/app.php | 3 + config/snappy.php | 19 + .../theme/backend/adminlte/invoice.blade.php | 8 +- routes/web.php | 1 + 7 files changed, 210 insertions(+), 206 deletions(-) create mode 100644 config/snappy.php diff --git a/app/Http/Controllers/UserHomeController.php b/app/Http/Controllers/UserHomeController.php index 7f95858..3f0143c 100644 --- a/app/Http/Controllers/UserHomeController.php +++ b/app/Http/Controllers/UserHomeController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use Illuminate\Support\Facades\Auth; use App\Models\Invoice; use App\User; +use PDF; class UserHomeController extends Controller { @@ -18,6 +19,11 @@ class UserHomeController extends Controller return View('invoice',['o'=>$o]); } + public function invoice_pdf(Invoice $o) + { + return PDF::loadView('invoice', ['o'=>$o])->stream(sprintf('%s.pdf',$o->invoice_account_id)); + } + public function home() { switch (Auth::user()->role()) { diff --git a/composer.json b/composer.json index e7bc355..9a374ac 100644 --- a/composer.json +++ b/composer.json @@ -11,11 +11,13 @@ "php": ">=7.2.0", "acacha/user": "^0.2.2", "barryvdh/laravel-debugbar": "^3.1", - "barryvdh/laravel-dompdf": "^0.8.2", + "barryvdh/laravel-snappy": "^0.4.1", "clarkeash/doorman": "^2.0", "creativeorange/gravatar": "^1.0", "doctrine/dbal": "^2.7", "fideloper/proxy": "^4.0", + "h4cc/wkhtmltoimage-amd64": "0.12.x", + "h4cc/wkhtmltopdf-amd64": "0.12.x", "intervention/image": "^2.4", "laravel/framework": "5.6.*", "laravel/passport": "^6.0", diff --git a/composer.lock b/composer.lock index 6267aa8..8170361 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "e6283e4f1d3de303b1abab3cc342c8cd", + "content-hash": "05d6e145f1dc63442830713daced798d", "packages": [ { "name": "acacha/user", @@ -129,41 +129,43 @@ "time": "2018-05-03T18:27:04+00:00" }, { - "name": "barryvdh/laravel-dompdf", - "version": "v0.8.2", + "name": "barryvdh/laravel-snappy", + "version": "v0.4.1", "source": { "type": "git", - "url": "https://github.com/barryvdh/laravel-dompdf.git", - "reference": "7dcdecfa125c174d0abe723603633dc2756ea3af" + "url": "https://github.com/barryvdh/laravel-snappy.git", + "reference": "5f6e7f3ba15c867d1b8e2885d454110270616ebe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/barryvdh/laravel-dompdf/zipball/7dcdecfa125c174d0abe723603633dc2756ea3af", - "reference": "7dcdecfa125c174d0abe723603633dc2756ea3af", + "url": "https://api.github.com/repos/barryvdh/laravel-snappy/zipball/5f6e7f3ba15c867d1b8e2885d454110270616ebe", + "reference": "5f6e7f3ba15c867d1b8e2885d454110270616ebe", "shasum": "" }, "require": { - "dompdf/dompdf": "^0.8", - "illuminate/support": "5.1.x|5.2.x|5.3.x|5.4.x|5.5.x|5.6.x", - "php": ">=5.5.9" + "illuminate/filesystem": "5.0.x|5.1.x|5.2.x|5.3.x|5.4.x|5.5.x|5.6.x", + "illuminate/support": "5.0.x|5.1.x|5.2.x|5.3.x|5.4.x|5.5.x|5.6.x", + "knplabs/knp-snappy": "^1", + "php": ">=5.4.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "0.8-dev" + "dev-master": "0.4-dev" }, "laravel": { "providers": [ - "Barryvdh\\DomPDF\\ServiceProvider" + "Barryvdh\\Snappy\\ServiceProvider" ], "aliases": { - "PDF": "Barryvdh\\DomPDF\\Facade" + "PDF": "Barryvdh\\Snappy\\Facades\\SnappyPdf", + "SnappyImage": "Barryvdh\\Snappy\\Facades\\SnappyImage" } } }, "autoload": { "psr-4": { - "Barryvdh\\DomPDF\\": "src" + "Barryvdh\\Snappy\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -176,13 +178,16 @@ "email": "barryvdh@gmail.com" } ], - "description": "A DOMPDF Wrapper for Laravel", + "description": "Snappy PDF/Image for Laravel 4", "keywords": [ - "dompdf", + "image", "laravel", - "pdf" + "pdf", + "snappy", + "wkhtmltoimage", + "wkhtmltopdf" ], - "time": "2018-02-07T17:43:25+00:00" + "time": "2018-02-08T15:58:26+00:00" }, { "name": "clarkeash/doorman", @@ -863,68 +868,6 @@ ], "time": "2014-09-09T13:34:57+00:00" }, - { - "name": "dompdf/dompdf", - "version": "v0.8.2", - "source": { - "type": "git", - "url": "https://github.com/dompdf/dompdf.git", - "reference": "5113accd9ae5d466077cce5208dcf3fb871bf8f6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/dompdf/dompdf/zipball/5113accd9ae5d466077cce5208dcf3fb871bf8f6", - "reference": "5113accd9ae5d466077cce5208dcf3fb871bf8f6", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-gd": "*", - "ext-mbstring": "*", - "phenx/php-font-lib": "0.5.*", - "phenx/php-svg-lib": "0.3.*", - "php": ">=5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "4.8.*", - "squizlabs/php_codesniffer": "2.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-develop": "0.7-dev" - } - }, - "autoload": { - "psr-4": { - "Dompdf\\": "src/" - }, - "classmap": [ - "lib/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-2.1" - ], - "authors": [ - { - "name": "Fabien Ménager", - "email": "fabien.menager@gmail.com" - }, - { - "name": "Brian Sweeney", - "email": "eclecticgeek@gmail.com" - }, - { - "name": "Gabriel Bull", - "email": "me@gabrielbull.com" - } - ], - "description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter", - "homepage": "https://github.com/dompdf/dompdf", - "time": "2017-11-26T14:49:08+00:00" - }, { "name": "dragonmantank/cron-expression", "version": "v2.2.0", @@ -1358,6 +1301,91 @@ ], "time": "2017-03-20T17:10:46+00:00" }, + { + "name": "h4cc/wkhtmltoimage-amd64", + "version": "0.12.4", + "source": { + "type": "git", + "url": "https://github.com/h4cc/wkhtmltoimage-amd64.git", + "reference": "c4e33f635207af89a704205b8902fb5715ca88be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/h4cc/wkhtmltoimage-amd64/zipball/c4e33f635207af89a704205b8902fb5715ca88be", + "reference": "c4e33f635207af89a704205b8902fb5715ca88be", + "shasum": "" + }, + "bin": [ + "bin/wkhtmltoimage-amd64" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL Version 3" + ], + "authors": [ + { + "name": "Julius Beckmann", + "email": "github@h4cc.de" + } + ], + "description": "Convert html to image using webkit (qtwebkit). Static linked linux binary for amd64 systems.", + "homepage": "http://wkhtmltopdf.org/", + "keywords": [ + "binary", + "convert", + "image", + "snapshot", + "thumbnail", + "wkhtmltoimage" + ], + "time": "2018-01-15T07:23:40+00:00" + }, + { + "name": "h4cc/wkhtmltopdf-amd64", + "version": "0.12.4", + "source": { + "type": "git", + "url": "https://github.com/h4cc/wkhtmltopdf-amd64.git", + "reference": "4e2ab2d032a5d7fbe2a741de8b10b8989523c95b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/h4cc/wkhtmltopdf-amd64/zipball/4e2ab2d032a5d7fbe2a741de8b10b8989523c95b", + "reference": "4e2ab2d032a5d7fbe2a741de8b10b8989523c95b", + "shasum": "" + }, + "bin": [ + "bin/wkhtmltopdf-amd64" + ], + "type": "library", + "autoload": { + "psr-4": { + "h4cc\\WKHTMLToPDF\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL Version 3" + ], + "authors": [ + { + "name": "Julius Beckmann", + "email": "github@h4cc.de" + } + ], + "description": "Convert html to pdf using webkit (qtwebkit). Static linked linux binary for amd64 systems.", + "homepage": "http://wkhtmltopdf.org/", + "keywords": [ + "binary", + "convert", + "pdf", + "snapshot", + "thumbnail", + "wkhtmltopdf" + ], + "time": "2018-01-15T06:57:33+00:00" + }, { "name": "igaster/laravel-theme", "version": "v2.0.6", @@ -1578,6 +1606,72 @@ ], "time": "2015-04-20T18:58:01+00:00" }, + { + "name": "knplabs/knp-snappy", + "version": "v1.0.4", + "source": { + "type": "git", + "url": "https://github.com/KnpLabs/snappy.git", + "reference": "144c4ecd1ccaeda936bf832b93079efc490e6850" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/KnpLabs/snappy/zipball/144c4ecd1ccaeda936bf832b93079efc490e6850", + "reference": "144c4ecd1ccaeda936bf832b93079efc490e6850", + "shasum": "" + }, + "require": { + "php": ">=5.6", + "psr/log": "^1.0", + "symfony/process": "~2.3 || ~3.0 || ~4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.8.36" + }, + "suggest": { + "h4cc/wkhtmltoimage-amd64": "Provides wkhtmltoimage-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency", + "h4cc/wkhtmltoimage-i386": "Provides wkhtmltoimage-i386 binary for Linux-compatible machines, use version `~0.12` as dependency", + "h4cc/wkhtmltopdf-amd64": "Provides wkhtmltopdf-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency", + "h4cc/wkhtmltopdf-i386": "Provides wkhtmltopdf-i386 binary for Linux-compatible machines, use version `~0.12` as dependency", + "wemersonjanuario/wkhtmltopdf-windows": "Provides wkhtmltopdf executable for Windows, use version `~0.12` as dependency" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Knp\\Snappy\\": "src/Knp/Snappy" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "KnpLabs Team", + "homepage": "http://knplabs.com" + }, + { + "name": "Symfony Community", + "homepage": "http://github.com/KnpLabs/snappy/contributors" + } + ], + "description": "PHP5 library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.", + "homepage": "http://github.com/KnpLabs/snappy", + "keywords": [ + "knp", + "knplabs", + "pdf", + "snapshot", + "thumbnail", + "wkhtmltopdf" + ], + "time": "2018-01-22T19:40:51+00:00" + }, { "name": "laravel/framework", "version": "v5.6.25", @@ -2960,83 +3054,6 @@ ], "time": "2018-06-08T15:26:40+00:00" }, - { - "name": "phenx/php-font-lib", - "version": "0.5.1", - "source": { - "type": "git", - "url": "https://github.com/PhenX/php-font-lib.git", - "reference": "760148820110a1ae0936e5cc35851e25a938bc97" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/PhenX/php-font-lib/zipball/760148820110a1ae0936e5cc35851e25a938bc97", - "reference": "760148820110a1ae0936e5cc35851e25a938bc97", - "shasum": "" - }, - "require-dev": { - "phpunit/phpunit": "^4.8" - }, - "type": "library", - "autoload": { - "psr-4": { - "FontLib\\": "src/FontLib" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-3.0" - ], - "authors": [ - { - "name": "Fabien Ménager", - "email": "fabien.menager@gmail.com" - } - ], - "description": "A library to read, parse, export and make subsets of different types of font files.", - "homepage": "https://github.com/PhenX/php-font-lib", - "time": "2017-09-13T16:14:37+00:00" - }, - { - "name": "phenx/php-svg-lib", - "version": "v0.3.2", - "source": { - "type": "git", - "url": "https://github.com/PhenX/php-svg-lib.git", - "reference": "ccc46ef6340d4b8a4a68047e68d8501ea961442c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/PhenX/php-svg-lib/zipball/ccc46ef6340d4b8a4a68047e68d8501ea961442c", - "reference": "ccc46ef6340d4b8a4a68047e68d8501ea961442c", - "shasum": "" - }, - "require": { - "sabberworm/php-css-parser": "8.1.*" - }, - "require-dev": { - "phpunit/phpunit": "~5.0" - }, - "type": "library", - "autoload": { - "psr-0": { - "Svg\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-3.0" - ], - "authors": [ - { - "name": "Fabien Ménager", - "email": "fabien.menager@gmail.com" - } - ], - "description": "A library to read, parse and export to PDF SVG files.", - "homepage": "https://github.com/PhenX/php-svg-lib", - "time": "2018-06-03T10:10:03+00:00" - }, { "name": "phpseclib/phpseclib", "version": "2.0.11", @@ -3522,50 +3539,6 @@ ], "time": "2018-01-20T00:28:24+00:00" }, - { - "name": "sabberworm/php-css-parser", - "version": "8.1.0", - "source": { - "type": "git", - "url": "https://github.com/sabberworm/PHP-CSS-Parser.git", - "reference": "850cbbcbe7fbb155387a151ea562897a67e242ef" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sabberworm/PHP-CSS-Parser/zipball/850cbbcbe7fbb155387a151ea562897a67e242ef", - "reference": "850cbbcbe7fbb155387a151ea562897a67e242ef", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "require-dev": { - "phpunit/phpunit": "*" - }, - "type": "library", - "autoload": { - "psr-0": { - "Sabberworm\\CSS": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Raphael Schweikert" - } - ], - "description": "Parser for CSS Files written in PHP", - "homepage": "http://www.sabberworm.com/blog/2010/6/10/php-css-parser", - "keywords": [ - "css", - "parser", - "stylesheet" - ], - "time": "2016-07-19T19:14:21+00:00" - }, { "name": "spatie/browsershot", "version": "3.22.1", diff --git a/config/app.php b/config/app.php index d4b1460..45d6706 100644 --- a/config/app.php +++ b/config/app.php @@ -169,6 +169,7 @@ return [ Orchestra\Asset\AssetServiceProvider::class, Collective\Html\HtmlServiceProvider::class, Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class, + Barryvdh\Snappy\ServiceProvider::class, ], /* @@ -209,6 +210,7 @@ return [ 'Mail' => Illuminate\Support\Facades\Mail::class, 'Notification' => Illuminate\Support\Facades\Notification::class, 'Password' => Illuminate\Support\Facades\Password::class, + 'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class, 'Queue' => Illuminate\Support\Facades\Queue::class, 'Redirect' => Illuminate\Support\Facades\Redirect::class, 'Redis' => Illuminate\Support\Facades\Redis::class, @@ -217,6 +219,7 @@ return [ 'Route' => Illuminate\Support\Facades\Route::class, 'Schema' => Illuminate\Support\Facades\Schema::class, 'Session' => Illuminate\Support\Facades\Session::class, + 'SnappyImage' => Barryvdh\Snappy\Facades\SnappyImage::class, 'Storage' => Illuminate\Support\Facades\Storage::class, 'URL' => Illuminate\Support\Facades\URL::class, 'Validator' => Illuminate\Support\Facades\Validator::class, diff --git a/config/snappy.php b/config/snappy.php new file mode 100644 index 0000000..5f1275b --- /dev/null +++ b/config/snappy.php @@ -0,0 +1,19 @@ + array( + 'enabled' => true, + 'binary' => '/var/www/html/vendor/bin/wkhtmltopdf-amd64', + 'timeout' => false, + 'options' => array('print-media-type' => true), + 'env' => array(), + ), + + 'image' => array( + 'enabled' => true, + 'binary' => '/var/www/html/vendor/bin/wkhtmltoimage', + 'timeout' => false, + 'options' => array(), + 'env' => array(), + ), +]; \ No newline at end of file diff --git a/resources/theme/backend/adminlte/invoice.blade.php b/resources/theme/backend/adminlte/invoice.blade.php index 49bc05d..9e1ef8c 100644 --- a/resources/theme/backend/adminlte/invoice.blade.php +++ b/resources/theme/backend/adminlte/invoice.blade.php @@ -8,7 +8,7 @@ Invoice # @endsection @section('contentheader_description') - {{ $o->invoice_id }} + {{ $o->invoice_account_id }} @endsection @section('main-content') @@ -202,9 +202,9 @@
Print - + + Download PDF +
diff --git a/routes/web.php b/routes/web.php index cffc3fd..ec6741a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -40,6 +40,7 @@ Route::group(['middleware'=>['theme:adminlte-be','auth','role:reseller'],'prefix Route::group(['middleware'=>['theme:adminlte-be','auth'],'prefix'=>'u'], function() { Route::get('home', 'UserHomeController@home'); Route::get('invoice/{o}', 'UserHomeController@invoice'); + Route::get('invoice/{o}/pdf','UserHomeController@invoice_pdf'); }); // Frontend Routes (Non-Authed Users)