Install beganovich/snappdf package

This commit is contained in:
Benjamin Beganović 2020-12-21 16:32:04 +01:00
parent 950a057496
commit 95c1f60674
4 changed files with 70 additions and 49 deletions

View File

@ -21,7 +21,7 @@ use App\Models\Account;
use App\Utils\CurlUtils; use App\Utils\CurlUtils;
use App\Utils\SystemHealth; use App\Utils\SystemHealth;
use App\Utils\Traits\AppSetup; use App\Utils\Traits\AppSetup;
use Beganovich\ChromiumPdf\ChromiumPdf; use Beganovich\Snappdf\Snappdf;
use DB; use DB;
use Exception; use Exception;
use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Foundation\Application;
@ -222,24 +222,13 @@ class SetupController extends Controller
return $this->testPhantom(); return $this->testPhantom();
} }
if (config('ninja.experimental_pdf_engine')) { $snappdf = new Snappdf();
$chromium_pdf = new ChromiumPdf();
$pdf = $chromium_pdf $pdf = $snappdf
->setChromiumPath(config('ninja.experimental_pdf_engine_chromium_path'))
->setHtml('GENERATING PDFs WORKS! Thank you for using Invoice Ninja!') ->setHtml('GENERATING PDFs WORKS! Thank you for using Invoice Ninja!')
->generate(); ->generate();
Storage::put('public/test.pdf', $pdf); Storage::put('public/test.pdf', $pdf);
} else {
Browsershot::html('GENERATING PDFs WORKS! Thank you for using Invoice Ninja!')
->setNodeBinary(config('ninja.system.node_path'))
->setNpmBinary(config('ninja.system.npm_path'))
->noSandbox()
->savePdf(
public_path('storage/test.pdf')
);
}
return response(['url' => asset('storage/test.pdf')], 200); return response(['url' => asset('storage/test.pdf')], 200);
} catch (Exception $e) { } catch (Exception $e) {

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Invoice Ninja (https://invoiceninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
@ -11,8 +12,7 @@
namespace App\Utils\Traits\Pdf; namespace App\Utils\Traits\Pdf;
use Beganovich\ChromiumPdf\ChromiumPdf; use Beganovich\Snappdf\Snappdf;
use Spatie\Browsershot\Browsershot;
trait PdfMaker trait PdfMaker
{ {
@ -27,31 +27,10 @@ trait PdfMaker
*/ */
public function makePdf($header, $footer, $html) public function makePdf($header, $footer, $html)
{ {
if (config('ninja.experimental_pdf_engine')) { $pdf = new Snappdf();
$pdf = new ChromiumPdf();
return $pdf return $pdf
->setChromiumPath(config('ninja.experimental_pdf_engine_chromium_path'))
->setHtml($html) ->setHtml($html)
->generate(); ->generate();
} }
$browser = Browsershot::html($html);
if (config('ninja.system.node_path')) {
$browser->setNodeBinary(config('ninja.system.node_path'));
}
if (config('ninja.system.npm_path')) {
$browser->setNpmBinary(config('ninja.system.npm_path'));
}
return $browser->deviceScaleFactor(1)
->showBackground()
->deviceScaleFactor(1)
->waitUntilNetworkIdle(true)
->noSandbox()
->ignoreHttpsErrors()
->pdf();
}
} }

View File

@ -27,11 +27,13 @@
"type": "project", "type": "project",
"require": { "require": {
"php": "^7.3|^7.4", "php": "^7.3|^7.4",
"ext-dom": "*",
"ext-json": "*", "ext-json": "*",
"ext-libxml": "*", "ext-libxml": "*",
"asgrim/ofxparser": "^1.2", "asgrim/ofxparser": "^1.2",
"authorizenet/authorizenet": "^2.0", "authorizenet/authorizenet": "^2.0",
"beganovich/chromium-pdf": "dev-master", "beganovich/chromium-pdf": "dev-master",
"beganovich/snappdf": "^1.0",
"checkout/checkout-sdk-php": "^1.0", "checkout/checkout-sdk-php": "^1.0",
"cleverit/ubl_invoice": "^1.3", "cleverit/ubl_invoice": "^1.3",
"composer/composer": "^2", "composer/composer": "^2",
@ -65,8 +67,7 @@
"stripe/stripe-php": "^7.50", "stripe/stripe-php": "^7.50",
"turbo124/beacon": "^1", "turbo124/beacon": "^1",
"turbo124/laravel-gmail": "^5.0", "turbo124/laravel-gmail": "^5.0",
"webpatser/laravel-countries": "dev-master#75992ad", "webpatser/laravel-countries": "dev-master#75992ad"
"ext-dom": "*"
}, },
"require-dev": { "require-dev": {
"anahkiasen/former": "^4.2", "anahkiasen/former": "^4.2",

58
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "591cb6a81d2d0b2f4cc0bf1db7fde22c", "content-hash": "5e9ee9e0cebf1e6f892c6b16d043de50",
"packages": [ "packages": [
{ {
"name": "asgrim/ofxparser", "name": "asgrim/ofxparser",
@ -248,6 +248,58 @@
}, },
"time": "2020-12-15T10:16:36+00:00" "time": "2020-12-15T10:16:36+00:00"
}, },
{
"name": "beganovich/snappdf",
"version": "v1.0.0",
"source": {
"type": "git",
"url": "https://github.com/beganovich/snappdf.git",
"reference": "96e0e2176f01ae712ab06dad0da6d2d79f7c1832"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/beganovich/snappdf/zipball/96e0e2176f01ae712ab06dad0da6d2d79f7c1832",
"reference": "96e0e2176f01ae712ab06dad0da6d2d79f7c1832",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-zip": "*",
"php": "^7.3|^7.4|^8.0",
"symfony/console": "^5.2",
"symfony/filesystem": "^5.2",
"symfony/process": "^5.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.17",
"phpunit/phpunit": "^9.5"
},
"bin": [
"snappdf"
],
"type": "library",
"autoload": {
"psr-4": {
"Beganovich\\Snappdf\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Benjamin Beganović",
"email": "k1pstabug@gmail.com"
}
],
"description": "Convert webpages or HTML into the PDF file using Chromium or Google Chrome.",
"support": {
"issues": "https://github.com/beganovich/snappdf/issues",
"source": "https://github.com/beganovich/snappdf/tree/v1.0.0"
},
"time": "2020-12-21T14:55:21+00:00"
},
{ {
"name": "brick/math", "name": "brick/math",
"version": "0.9.1", "version": "0.9.1",
@ -13890,9 +13942,9 @@
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
"php": "^7.3|^7.4", "php": "^7.3|^7.4",
"ext-dom": "*",
"ext-json": "*", "ext-json": "*",
"ext-libxml": "*", "ext-libxml": "*"
"ext-dom": "*"
}, },
"platform-dev": [], "platform-dev": [],
"plugin-api-version": "2.0.0" "plugin-api-version": "2.0.0"