Skip to content

Commit 4b77d98

Browse files
committed
Adds dompdf options
1 parent 399c735 commit 4b77d98

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{
77
"name": "David Lun",
88
"email": "[email protected]",
9-
"homepage": "https://lun.lt",
9+
"homepage": "https://davidlun.com",
1010
"role": "Developer"
1111
}
1212
],
@@ -15,8 +15,8 @@
1515
"require": {
1616
"php": "^7.3|^8.0",
1717
"barryvdh/laravel-dompdf": "^v2.0",
18-
"illuminate/http": "^5.5|^6|^7|^8|^9",
19-
"illuminate/support": "^5.5|^6|^7|^8|^9",
18+
"illuminate/http": "^5.5|^6|^7|^8|^9|^10",
19+
"illuminate/support": "^5.5|^6|^7|^8|^9|^10",
2020
"symfony/http-foundation": "^4.0|^5.0|^6.0"
2121
},
2222
"require-dev": {

config/invoices.php

+18
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
return [
44
'date' => [
5+
56
/*
67
* Carbon date format
78
*/
89
'format' => 'Y-m-d',
10+
911
/*
1012
* Due date for payment since invoice's date.
1113
*/
@@ -15,11 +17,13 @@
1517
'serial_number' => [
1618
'series' => 'AA',
1719
'sequence' => 1,
20+
1821
/*
1922
* Sequence will be padded accordingly, for ex. 00001
2023
*/
2124
'sequence_padding' => 5,
2225
'delimiter' => '.',
26+
2327
/*
2428
* Supported tags {SERIES}, {DELIMITER}, {SEQUENCE}
2529
* Example: AA.00001
@@ -29,6 +33,7 @@
2933

3034
'currency' => [
3135
'code' => 'eur',
36+
3237
/*
3338
* Usually cents
3439
* Used when spelling out the amount and if your currency has decimals.
@@ -37,19 +42,23 @@
3742
*/
3843
'fraction' => 'ct.',
3944
'symbol' => '',
45+
4046
/*
4147
* Example: 19.00
4248
*/
4349
'decimals' => 2,
50+
4451
/*
4552
* Example: 1.99
4653
*/
4754
'decimal_point' => '.',
55+
4856
/*
4957
* By default empty.
5058
* Example: 1,999.00
5159
*/
5260
'thousands_separator' => '',
61+
5362
/*
5463
* Supported tags {VALUE}, {SYMBOL}, {CODE}
5564
* Example: 1.99 €
@@ -94,4 +103,13 @@
94103
],
95104
],
96105
],
106+
107+
'dompdf_options' => [
108+
'enable_php' => true,
109+
/**
110+
* Do not write log.html or make it optional
111+
* @see https://github.com/dompdf/dompdf/issues/2810
112+
*/
113+
'logOutputFile' => '/dev/null',
114+
],
97115
];

src/Invoice.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace LaravelDaily\Invoices;
44

5-
use Barryvdh\DomPDF\Facade\Pdf;
5+
use Barryvdh\DomPDF\Facade\Pdf as PDF;
66
use Carbon\Carbon;
77
use Exception;
88
use Illuminate\Http\Response;
@@ -131,7 +131,7 @@ class Invoice
131131
public $table_columns;
132132

133133
/**
134-
* @var Pdf
134+
* @var PDF
135135
*/
136136
public $pdf;
137137

@@ -150,6 +150,11 @@ class Invoice
150150
*/
151151
protected array $paperOptions;
152152

153+
/**
154+
* @var array
155+
*/
156+
protected $options;
157+
153158
/**
154159
* Invoice constructor.
155160
*
@@ -189,9 +194,12 @@ public function __construct($name = '')
189194
$this->currency_thousands_separator = config('invoices.currency.thousands_separator');
190195
$this->currency_format = config('invoices.currency.format');
191196

192-
//Paper
197+
// Paper
193198
$this->paperOptions = config('invoices.paper');
194199

200+
// DomPDF options
201+
$this->options = config(['invoices.dompdf_options']) ?? ['enable_php' => true];
202+
195203
$this->disk = config('invoices.disk');
196204
$this->table_columns = static::TABLE_COLUMNS;
197205
}
@@ -265,7 +273,9 @@ public function render()
265273
$view = View::make($template, ['invoice' => $this]);
266274
$html = mb_convert_encoding($view, 'HTML-ENTITIES', 'UTF-8');
267275

268-
$this->pdf = Pdf::setOption(['enable_php' => true])->setPaper($this->paperOptions['size'], $this->paperOptions['orientation'])->loadHtml($html);
276+
$this->pdf = PDF::setOptions($this->options)
277+
->setPaper($this->paperOptions['size'], $this->paperOptions['orientation'])
278+
->loadHtml($html);
269279
$this->output = $this->pdf->output();
270280

271281
return $this;

0 commit comments

Comments
 (0)