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\SystemHealth;
use App\Utils\Traits\AppSetup;
use Beganovich\ChromiumPdf\ChromiumPdf;
use Beganovich\Snappdf\Snappdf;
use DB;
use Exception;
use Illuminate\Contracts\Foundation\Application;
@ -222,24 +222,13 @@ class SetupController extends Controller
return $this->testPhantom();
}
if (config('ninja.experimental_pdf_engine')) {
$chromium_pdf = new ChromiumPdf();
$snappdf = new Snappdf();
$pdf = $chromium_pdf
->setChromiumPath(config('ninja.experimental_pdf_engine_chromium_path'))
->setHtml('GENERATING PDFs WORKS! Thank you for using Invoice Ninja!')
->generate();
$pdf = $snappdf
->setHtml('GENERATING PDFs WORKS! Thank you for using Invoice Ninja!')
->generate();
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')
);
}
Storage::put('public/test.pdf', $pdf);
return response(['url' => asset('storage/test.pdf')], 200);
} catch (Exception $e) {

View File

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

View File

@ -27,11 +27,13 @@
"type": "project",
"require": {
"php": "^7.3|^7.4",
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
"asgrim/ofxparser": "^1.2",
"authorizenet/authorizenet": "^2.0",
"beganovich/chromium-pdf": "dev-master",
"beganovich/snappdf": "^1.0",
"checkout/checkout-sdk-php": "^1.0",
"cleverit/ubl_invoice": "^1.3",
"composer/composer": "^2",
@ -65,8 +67,7 @@
"stripe/stripe-php": "^7.50",
"turbo124/beacon": "^1",
"turbo124/laravel-gmail": "^5.0",
"webpatser/laravel-countries": "dev-master#75992ad",
"ext-dom": "*"
"webpatser/laravel-countries": "dev-master#75992ad"
},
"require-dev": {
"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",
"This file is @generated automatically"
],
"content-hash": "591cb6a81d2d0b2f4cc0bf1db7fde22c",
"content-hash": "5e9ee9e0cebf1e6f892c6b16d043de50",
"packages": [
{
"name": "asgrim/ofxparser",
@ -248,6 +248,58 @@
},
"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",
"version": "0.9.1",
@ -13890,9 +13942,9 @@
"prefer-lowest": false,
"platform": {
"php": "^7.3|^7.4",
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-dom": "*"
"ext-libxml": "*"
},
"platform-dev": [],
"plugin-api-version": "2.0.0"