| Path : /var/www/html/thb_loan_system/app/Services/ |
|
B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H |
| Current File : //var/www/html/thb_loan_system/app/Services/Pdf.php |
<?php
namespace App\Services;
use Illuminate\Support\Facades\View;
use Mpdf\Config\ConfigVariables;
use Mpdf\Config\FontVariables;
use Mpdf\Mpdf;
use Mpdf\Output\Destination;
class Pdf
{
public string $html;
public Mpdf $pdf;
public string $paperType;
public string $orientation = "portrait";
public static function loadView(string $view, $data = []): self
{
return (new Pdf)->setHtml(View::make($view,$data));
}
public function setPaper($paperType='A4', $orientation='P'): self
{
$this->paperType = $paperType;
if (!in_array($orientation,['L','P','landscape','portrait'])){
$orientation='P';
}
$this->orientation = $orientation;
return $this;
}
/**
* @param string $view
* @return $this
*/
public function setHtml(string $view): self
{
$this->html = $view;
$this->config();
return $this;
}
protected function config(): Mpdf
{
$defaultConfig = (new ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$this->pdf = new Mpdf([
'mode' => 'utf-8',
'format' => 'A4',
'orientation' => $this->orientation,
'fontDir' => array_merge($fontDirs, [
public_path('fonts'),
]),
'fontdata' => $fontData + [
'khmeros' => [
'R' => 'KhmerOS.ttf',
'useOTL' => 0xFF,
'useKashida' => 77,
]
],
'default_font' => 'khmeros'
]);
return $this->pdf;
}
public function download(string $filename): ?string
{
$this->pdf->AddPage($this->orientation,'','','','',7,7,7,7,7,7);
$this->pdf->WriteHTML($this->html);
return $this->pdf->Output($filename, Destination::DOWNLOAD);
}
}