Changeset View
Changeset View
Standalone View
Standalone View
src/app/Documents/Receipt.php
Show First 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | public function pdfOutput(): string | ||||
symlink( | symlink( | ||||
public_path('fonts/Roboto-Bold.ttf'), | public_path('fonts/Roboto-Bold.ttf'), | ||||
storage_path('fonts/Roboto-Bold.ttf') | storage_path('fonts/Roboto-Bold.ttf') | ||||
); | ); | ||||
} | } | ||||
// Fix font and image paths | // Fix font and image paths | ||||
$html = str_replace('url(/fonts/', 'url(fonts/', $html); | $html = str_replace('url(/fonts/', 'url(fonts/', $html); | ||||
$html = str_replace('src="/images/', 'src="images/', $html); | $html = str_replace('src="/', 'src="', $html); | ||||
// TODO: The output file is about ~200KB, we could probably slim it down | // TODO: The output file is about ~200KB, we could probably slim it down | ||||
// by using separate font files with small subset of languages when | // by using separate font files with small subset of languages when | ||||
// there are no Unicode characters used, e.g. only ASCII or Latin. | // there are no Unicode characters used, e.g. only ASCII or Latin. | ||||
// Load PDF generator | // Load PDF generator | ||||
$pdf = \PDF::loadHTML($html)->setPaper('a4', 'portrait'); | $pdf = \PDF::loadHTML($html)->setPaper('a4', 'portrait'); | ||||
▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | class Receipt | ||||
{ | { | ||||
$header = \config('app.company.name') . "\n" . \config('app.company.address'); | $header = \config('app.company.name') . "\n" . \config('app.company.address'); | ||||
$header = str_replace("\n", '<br>', htmlentities($header)); | $header = str_replace("\n", '<br>', htmlentities($header)); | ||||
$footerLineLength = 110; | $footerLineLength = 110; | ||||
$footer = \config('app.company.details'); | $footer = \config('app.company.details'); | ||||
$contact = \config('app.company.email'); | $contact = \config('app.company.email'); | ||||
$logo = \config('app.company.logo'); | $logo = \config('app.company.logo'); | ||||
$theme = \config('app.theme'); | |||||
if ($contact) { | if ($contact) { | ||||
$length = strlen($footer) + strlen($contact) + 3; | $length = strlen($footer) + strlen($contact) + 3; | ||||
$contact = htmlentities($contact); | $contact = htmlentities($contact); | ||||
$footer .= ($length > $footerLineLength ? "\n" : ' | ') | $footer .= ($length > $footerLineLength ? "\n" : ' | ') | ||||
. sprintf('<a href="mailto:%s">%s</a>', $contact, $contact); | . sprintf('<a href="mailto:%s">%s</a>', $contact, $contact); | ||||
} | } | ||||
if ($logo && strpos($logo, '/') === false) { | |||||
$logo = "/themes/$theme/images/$logo"; | |||||
} | |||||
return [ | return [ | ||||
'logo' => $logo ? "<img src=\"/images/$logo\" width=300>" : '', | 'logo' => $logo ? "<img src=\"$logo\" width=300>" : '', | ||||
'header' => $header, | 'header' => $header, | ||||
'footer' => $footer, | 'footer' => $footer, | ||||
]; | ]; | ||||
} | } | ||||
} | } |