1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-06 03:02:34 +01:00

Experimental PDF rendering:

- Added experimental flag in ninja.php
- Added experimental rendering in PdfMaker.php
- Added dynamic $global-margin for 1cm/0cm based on PDF method
This commit is contained in:
Benjamin Beganović 2020-12-14 17:23:04 +01:00
parent 98130f2105
commit dcd6574b2d
13 changed files with 73 additions and 15 deletions

View File

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

View File

@ -11,6 +11,7 @@
namespace App\Utils\Traits\Pdf; namespace App\Utils\Traits\Pdf;
use Beganovich\ChromiumPdf\ChromiumPdf;
use Spatie\Browsershot\Browsershot; use Spatie\Browsershot\Browsershot;
trait PdfMaker trait PdfMaker
@ -26,6 +27,15 @@ trait PdfMaker
*/ */
public function makePdf($header, $footer, $html) public function makePdf($header, $footer, $html)
{ {
if (config('ninja.experimental_pdf_engine')) {
$pdf = new ChromiumPdf();
return $pdf
->setChromiumPath(config('ninja.experimental_pdf_engine_chromium_path'))
->setHtml($html)
->generate();
}
$browser = Browsershot::html($html); $browser = Browsershot::html($html);
if (config('ninja.system.node_path')) { if (config('ninja.system.node_path')) {

View File

@ -29,6 +29,7 @@
"ext-json": "*", "ext-json": "*",
"asgrim/ofxparser": "^1.2", "asgrim/ofxparser": "^1.2",
"authorizenet/authorizenet": "^2.0", "authorizenet/authorizenet": "^2.0",
"beganovich/chromium-pdf": "dev-master",
"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",

47
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": "35318cb6b03b84487f53dc09f2262030", "content-hash": "75cb7287f45830678381d8e27486cf4a",
"packages": [ "packages": [
{ {
"name": "asgrim/ofxparser", "name": "asgrim/ofxparser",
@ -204,6 +204,50 @@
}, },
"time": "2020-12-11T19:12:18+00:00" "time": "2020-12-11T19:12:18+00:00"
}, },
{
"name": "beganovich/chromium-pdf",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/beganovich/chromium-pdf.git",
"reference": "0f1641f0f8272b68aa4942307b85fba5596a90c3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/beganovich/chromium-pdf/zipball/0f1641f0f8272b68aa4942307b85fba5596a90c3",
"reference": "0f1641f0f8272b68aa4942307b85fba5596a90c3",
"shasum": ""
},
"require": {
"php": "^7.3|^7.4|^8.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
},
"default-branch": true,
"type": "library",
"autoload": {
"psr-4": {
"Beganovich\\ChromiumPdf\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Benjamin Beganović",
"email": "k1pstabug@gmail.com"
}
],
"description": "Generate PDFs using headless Chromium",
"support": {
"issues": "https://github.com/beganovich/chromium-pdf/issues",
"source": "https://github.com/beganovich/chromium-pdf/tree/master"
},
"time": "2020-12-14T15:49:17+00:00"
},
{ {
"name": "brick/math", "name": "brick/math",
"version": "0.9.1", "version": "0.9.1",
@ -13836,6 +13880,7 @@
"aliases": [], "aliases": [],
"minimum-stability": "dev", "minimum-stability": "dev",
"stability-flags": { "stability-flags": {
"beganovich/chromium-pdf": 20,
"webpatser/laravel-countries": 20 "webpatser/laravel-countries": 20
}, },
"prefer-stable": true, "prefer-stable": true,

View File

@ -135,4 +135,6 @@ return [
'designs' => [ 'designs' => [
'base_path' => resource_path('views/pdf-designs/'), 'base_path' => resource_path('views/pdf-designs/'),
], ],
'experimental_pdf_engine' => env('EXPERIMENTAL_PDF_ENGINE', false),
'experimental_pdf_engine_chromium_path' => env('EXPERIMENTAL_PDF_ENGINE_CHROMIUM_PATH', null),
]; ];

View File

@ -14,6 +14,7 @@
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
margin: "$global-margin";
} }
p { p {

View File

@ -12,7 +12,7 @@
} }
@page { @page {
margin: 1cm; margin: "$global-margin";
} }
p { p {

View File

@ -9,7 +9,7 @@
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
font-size: "$font_size"; font-size: "$font_size";
margin: 1cm; margin: "$global-margin";
} }
p { p {

View File

@ -30,7 +30,7 @@
} }
body { body {
margin: 2rem; margin: "$global-margin";
} }
.header-wrapper { .header-wrapper {

View File

@ -17,7 +17,7 @@
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
margin: 1cm; margin: "$global-margin";
} }
.company-logo-wrapper { .company-logo-wrapper {

View File

@ -20,7 +20,7 @@
} }
@page { @page {
margin: 1cm; margin: "$global-margin";
} }
.header-wrapper { .header-wrapper {

View File

@ -13,7 +13,7 @@
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
margin: 1cm; margin: "$global-margin";
} }
.header-wrapper { .header-wrapper {

View File

@ -17,7 +17,7 @@
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
margin: 1cm; margin: "$global-margin";
} }
.header-wrapper { .header-wrapper {