1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +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['$global-margin'] = ['value' => 'm-8', 'label' => ''];
$data['$global-padding'] = ['value' => 'p-8', 'label' => ''];
$data['$global-margin'] = ['value' => config('ninja.experimental_pdf_engine') ? '0cm' : '1cm', 'label' => ''];
$data['$tax'] = ['value' => '', 'label' => ctrans('texts.tax')];
$data['$app_url'] = ['value' => $this->generateAppUrl(), 'label' => ''];
$data['$from'] = ['value' => '', 'label' => ctrans('texts.from')];
@ -155,7 +154,7 @@ class HtmlEngine
} else {
$data['$balance_due'] = ['value' => Number::formatMoney($this->entity->balance, $this->client) ?: ' ', 'label' => ctrans('texts.balance_due')];
}
$data['$quote.balance_due'] = $data['$balance_due'];
$data['$invoice.balance_due'] = $data['$balance_due'];
$data['$balance_due'] = $data['$balance_due'];
@ -243,7 +242,7 @@ class HtmlEngine
$data['$client.postal_city_state'] = &$data['$postal_city_state'];
$data['$client.country'] = &$data['$country'];
$data['$client.email'] = &$data['$email'];
$data['$client.currency'] = ['value' => $this->client->currency()->code, 'label' => ''];
$data['$client.balance'] = ['value' => Number::formatMoney($this->client->balance, $this->client), 'label' => ctrans('texts.account_balance')];

View File

@ -11,6 +11,7 @@
namespace App\Utils\Traits\Pdf;
use Beganovich\ChromiumPdf\ChromiumPdf;
use Spatie\Browsershot\Browsershot;
trait PdfMaker
@ -26,6 +27,15 @@ trait PdfMaker
*/
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);
if (config('ninja.system.node_path')) {

View File

@ -29,6 +29,7 @@
"ext-json": "*",
"asgrim/ofxparser": "^1.2",
"authorizenet/authorizenet": "^2.0",
"beganovich/chromium-pdf": "dev-master",
"checkout/checkout-sdk-php": "^1.0",
"cleverit/ubl_invoice": "^1.3",
"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",
"This file is @generated automatically"
],
"content-hash": "35318cb6b03b84487f53dc09f2262030",
"content-hash": "75cb7287f45830678381d8e27486cf4a",
"packages": [
{
"name": "asgrim/ofxparser",
@ -204,6 +204,50 @@
},
"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",
"version": "0.9.1",
@ -13836,6 +13880,7 @@
"aliases": [],
"minimum-stability": "dev",
"stability-flags": {
"beganovich/chromium-pdf": 20,
"webpatser/laravel-countries": 20
},
"prefer-stable": true,

View File

@ -32,7 +32,7 @@ return [
'phantomjs_secret' => env('PHANTOMJS_SECRET', false),
'phantomjs_pdf_generation' => env('PHANTOMJS_PDF_GENERATION', true),
'trusted_proxies' => env('TRUSTED_PROXIES', false),
'sentry_dsn' => env('SENTRY_LARAVEL_DSN', 'https://9b4e15e575214354a7d666489783904a@sentry.invoicing.co/6'),
'environment' => env('NINJA_ENVIRONMENT', 'selfhost'), // 'hosted', 'development', 'selfhost', 'reseller'
@ -135,4 +135,6 @@ return [
'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;
-moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif;
margin: "$global-margin";
}
p {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -13,7 +13,7 @@
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-family: Arial, Helvetica, sans-serif;
margin: 1cm;
margin: "$global-margin";
}
.header-wrapper {
@ -58,8 +58,8 @@
flex-direction: column;
}
#product-table,
#delivery-note-table,
#product-table,
#delivery-note-table,
#task-table {
min-width: 100%;
table-layout: fixed;

View File

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