Skip to content

Commit 00b9ba2

Browse files
authored
Merge pull request #17989 from grokability/fixes-tcpdf-png-handling
Fixed #17940 - pngs not showing in acceptance PDFs
2 parents 7360e09 + f1e3bc9 commit 00b9ba2

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

app/Http/Controllers/Account/AcceptanceController.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public function store(Request $request, $id) : RedirectResponse
7777
$acceptance = CheckoutAcceptance::find($id);
7878
$assigned_user = User::find($acceptance->assigned_to_id);
7979
$settings = Setting::getSettings();
80-
$path_logo = '';
8180
$sig_filename='';
8281

8382

@@ -138,6 +137,13 @@ public function store(Request $request, $id) : RedirectResponse
138137
}
139138

140139

140+
// Convert PDF logo to base64 for TCPDF
141+
// This is needed for TCPDF to properly embed the image if it's a png and the cache isn't writable
142+
$encoded_logo = null;
143+
if ($settings->acceptance_pdf_logo) {
144+
$encoded_logo = base64_encode(file_get_contents(public_path() . '/uploads/' . $settings->acceptance_pdf_logo));
145+
}
146+
141147
// Get the data array ready for the notifications and PDF generation
142148
$data = [
143149
'item_tag' => $item->asset_tag,
@@ -153,8 +159,8 @@ public function store(Request $request, $id) : RedirectResponse
153159
'assigned_to' => $assigned_user->display_name,
154160
'site_name' => $settings->site_name,
155161
'company_name' => $item->company?->name?? $settings->site_name,
156-
'signature' => ($sig_filename) ? storage_path() . '/private_uploads/signatures/' . $sig_filename : null,
157-
'logo' => ($settings->acceptance_pdf_logo) ? public_path() . '/uploads/' . $settings->acceptance_pdf_logo : null,
162+
'signature' => (($sig_filename && array_key_exists('1', $encoded_image))) ? $encoded_image[1] : null,
163+
'logo' => ($encoded_logo) ?? null,
158164
'date_settings' => $settings->date_display_format,
159165
'admin' => auth()->user()->present()?->fullName,
160166
'qty' => $acceptance->qty ?? 1,

app/Models/CheckoutAcceptance.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function generateAcceptancePdf($data, $pdf_filename) {
184184

185185
$pdf->AddPage();
186186
if ($data['logo'] != null) {
187-
$pdf->writeHTML('<img src="'.$data['logo'].'">', true, 0, true, 0, '');
187+
$pdf->writeHTML('<img src="@'.$data['logo'].'">', true, 0, true, 0, '');
188188
} else {
189189
$pdf->writeHTML('<h3>'.$data['site_name'].'</h3><br /><br />', true, 0, true, 0, 'C');
190190
}
@@ -230,7 +230,7 @@ public function generateAcceptancePdf($data, $pdf_filename) {
230230
$pdf->Ln();
231231

232232
if ($data['signature'] != null) {
233-
$pdf->writeHTML('<img src="'.$data['signature'].'">', true, 0, true, 0, '');
233+
$pdf->writeHTML('<img src="@'.$data['signature'].'">', true, 0, true, 0, '');
234234
$pdf->writeHTML('<hr>', true, 0, true, 0, '');
235235
$pdf->writeHTML(e($data['assigned_to']), true, 0, true, 0, 'C');
236236
$pdf->Ln();

0 commit comments

Comments
 (0)