Skip to content

Commit 609c681

Browse files
committed
default fonts with fallback
1 parent 848dad7 commit 609c681

File tree

6 files changed

+41
-46
lines changed

6 files changed

+41
-46
lines changed

README.md

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,30 +109,48 @@ return [
109109
'company_number' => null,
110110
],
111111

112-
'default_logo' => null,
113-
114-
'default_color' => '#050038',
115-
116-
'default_template' => 'default.layout',
117-
118112
/**
119113
* ISO 4217 currency code
120114
*/
121115
'default_currency' => 'USD',
122116

123-
/**
124-
* Default DOM PDF options
125-
*
126-
* @see Available options https://github.com/barryvdh/laravel-dompdf#configuration
127-
*/
128-
'pdf_options' => [
129-
'isPhpEnabled' => true,
130-
],
117+
'pdf' => [
118+
/**
119+
* Default DOM PDF options
120+
*
121+
* @see Available options https://github.com/barryvdh/laravel-dompdf#configuration
122+
*/
123+
'options' => [
124+
'isPhpEnabled' => true,
125+
'fontHeightRatio' => 0.9,
126+
/**
127+
* Supported values are: 'DejaVu Sans', 'Helvetica', 'Courier', 'Times', 'Symbol', 'ZapfDingbats'
128+
*/
129+
'defaultFont' => 'DejaVu Sans',
130+
],
131+
132+
'paper' => [
133+
'paper' => 'a4',
134+
'orientation' => 'portrait',
135+
],
136+
137+
/**
138+
* The logo displayed in the PDF
139+
*/
140+
'logo' => null,
141+
142+
/**
143+
* The color displayed at the top of the PDF
144+
*/
145+
'color' => '#050038',
146+
147+
/**
148+
* The template used to render the PDF
149+
*/
150+
'template' => 'default.layout',
131151

132-
'paper_options' => [
133-
'paper' => 'a4',
134-
'orientation' => 'portrait',
135152
],
153+
136154
];
137155
```
138156

config/invoices.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
* @see Available options https://github.com/barryvdh/laravel-dompdf#configuration
8787
*/
8888
'options' => [
89-
'isRemoteEnabled' => true,
9089
'isPhpEnabled' => true,
9190
'fontHeightRatio' => 0.9,
9291
/**
@@ -100,19 +99,6 @@
10099
'orientation' => 'portrait',
101100
],
102101

103-
/**
104-
* Custom font loadable
105-
*/
106-
'custom_fonts' => [
107-
'Noto Sans' => 'https://fonts.googleapis.com/css2?family=Noto+Sans&display=swap"',
108-
'Plus Jakarta Sans' => 'https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans&display=swap',
109-
],
110-
111-
/**
112-
* The font used for the PDF
113-
*/
114-
'font' => 'Noto Sans',
115-
116102
/**
117103
* The logo displayed in the PDF
118104
*/

resources/views/default/invoice.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121

2222
<table class="w-full">
2323
<tbody>
24-
<tr class="text-sm">
25-
<td class="whitespace-nowrap pr-2">
24+
<tr class="">
25+
<td class="whitespace-nowrap pr-2 text-sm">
2626
<strong>{{ __('invoices::invoice.serial_number') }} </strong>
2727
</td>
28-
<td class="" width="100%">
28+
<td class="whitespace-nowrap text-sm" width="100%">
2929
<strong>{{ $invoice->serial_number }}</strong>
3030
</td>
3131
</tr>

resources/views/default/layout.blade.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55
<title>{{ $invoice->name }}</title>
66
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
77

8-
@if ($invoice->font && isset($customFonts[$invoice->font]))
9-
<link href="{{ $customFonts[$invoice->font] }}" rel="stylesheet">
10-
@endif
11-
128
@include('invoices::default.style')
139
</head>
1410

15-
<body style="font-family: {{ $invoice->font }};">
11+
<body>
1612

1713
@include('invoices::default.invoice')
1814

resources/views/default/style.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
margin: 0;
44
line-height: 1.5;
55
tab-size: 4;
6-
font-family: 'DejaVu Sans', 'Helvetica', 'Courier', 'Times', 'Symbol', 'ZapfDingbats';
6+
font-family: '{{ $invoice->font }}', 'DejaVu Sans', 'Helvetica', 'Courier', 'Times', 'Symbol', 'ZapfDingbats';
77
font-feature-settings: normal;
88
font-variation-settings: normal;
99
}

src/PdfInvoice.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,14 @@ public function __construct(
3636
public ?string $color = null,
3737
public ?string $filename = null,
3838
public ?string $template = null,
39-
/**
40-
* Can be a standard or custom font name
41-
*/
4239
public ?string $font = null,
4340
) {
4441
$this->name = $name ?? __('invoices::invoice.invoice');
4542
$this->seller = $seller ?? config('invoices.default_seller', []);
4643
$this->logo = $logo ?? config('invoices.pdf.logo') ?? config('invoices.default_logo');
4744
$this->color = $color ?? config('invoices.pdf.color') ?? config('invoices.default_color');
45+
$this->font = $font ?? config('invoices.pdf.options.defaultFont');
4846
$this->template = sprintf('invoices::%s', $template ?? config('invoices.pdf.template') ?? config('invoices.default_template'));
49-
50-
$this->font = $font ?? config('invoices.pdf.font');
5147
}
5248

5349
public function generateFilename(): string
@@ -139,7 +135,6 @@ public function pdf(array $options = []): \Barryvdh\DomPDF\PDF
139135

140136
return $pdf->loadView($this->template, [
141137
'invoice' => $this,
142-
'customFonts' => config('invoices.pdf.custom_fonts') ?? [],
143138
]);
144139
}
145140

0 commit comments

Comments
 (0)