1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Merge pull request #4549 from beganovich/v5-snappdf-integration

(v5) snappdf support
This commit is contained in:
Benjamin Beganović 2020-12-22 09:31:22 +01:00 committed by GitHub
commit 69bc664457
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 67 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

@ -92,7 +92,7 @@ class HtmlEngine
}
$data = [];
$data['$global_margin'] = ['value' => config('ninja.experimental_pdf_engine') ? '0cm' : '1cm', 'label' => ''];
$data['$global_margin'] = ['value' => '1cm', 'label' => ''];
$data['$tax'] = ['value' => '', 'label' => ctrans('texts.tax')];
$data['$app_url'] = ['value' => $this->generateAppUrl(), 'label' => ''];
$data['$from'] = ['value' => '', 'label' => ctrans('texts.from')];

View File

@ -74,8 +74,8 @@ class SystemHealth
'env_writable' => self::checkEnvWritable(),
//'mail' => self::testMailServer(),
'simple_db_check' => (bool) self::simpleDbCheck(),
'npm_status' => self::checkNpm(),
'node_status' => self::checkNode(),
// 'npm_status' => self::checkNpm(),
// 'node_status' => self::checkNode(),
'cache_enabled' => self::checkConfigCache(),
'phantom_enabled' => (bool) config('ninja.phantomjs_pdf_generation'),
'exec' => (bool) self::checkExecWorks(),

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,12 @@
"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 +66,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",

41
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": "669af9e67b79e872aa671420cfb14ddd",
"packages": [
{
"name": "asgrim/ofxparser",
@ -205,30 +205,38 @@
"time": "2020-12-18T19:12:13+00:00"
},
{
"name": "beganovich/chromium-pdf",
"version": "dev-master",
"name": "beganovich/snappdf",
"version": "v1.0.0",
"source": {
"type": "git",
"url": "https://github.com/beganovich/chromium-pdf.git",
"reference": "f6f32bb99616a1c1b7108250ccc438210134a99f"
"url": "https://github.com/beganovich/snappdf.git",
"reference": "96e0e2176f01ae712ab06dad0da6d2d79f7c1832"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/beganovich/chromium-pdf/zipball/f6f32bb99616a1c1b7108250ccc438210134a99f",
"reference": "f6f32bb99616a1c1b7108250ccc438210134a99f",
"url": "https://api.github.com/repos/beganovich/snappdf/zipball/96e0e2176f01ae712ab06dad0da6d2d79f7c1832",
"reference": "96e0e2176f01ae712ab06dad0da6d2d79f7c1832",
"shasum": ""
},
"require": {
"php": "^7.3|^7.4|^8.0"
"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"
},
"default-branch": true,
"bin": [
"snappdf"
],
"type": "library",
"autoload": {
"psr-4": {
"Beganovich\\ChromiumPdf\\": "src/"
"Beganovich\\Snappdf\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
@ -241,12 +249,12 @@
"email": "k1pstabug@gmail.com"
}
],
"description": "Generate PDFs using headless Chromium",
"description": "Convert webpages or HTML into the PDF file using Chromium or Google Chrome.",
"support": {
"issues": "https://github.com/beganovich/chromium-pdf/issues",
"source": "https://github.com/beganovich/chromium-pdf/tree/master"
"issues": "https://github.com/beganovich/snappdf/issues",
"source": "https://github.com/beganovich/snappdf/tree/v1.0.0"
},
"time": "2020-12-15T10:16:36+00:00"
"time": "2020-12-21T14:55:21+00:00"
},
{
"name": "brick/math",
@ -13883,16 +13891,15 @@
"aliases": [],
"minimum-stability": "dev",
"stability-flags": {
"beganovich/chromium-pdf": 20,
"webpatser/laravel-countries": 20
},
"prefer-stable": true,
"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"

View File

@ -96,6 +96,8 @@ class ImportCsvTest extends TestCase
public function testClientCsvImport()
{
$this->markTestSkipped();
$csv = file_get_contents(base_path().'/tests/Feature/Import/clients.csv');
$hash = Str::random(32);
$column_map = [