生成pdf
This commit is contained in:
@@ -156,14 +156,34 @@ class MpdfDriver
|
||||
|
||||
$mpdf->WriteHTML($html);
|
||||
|
||||
foreach ($car['attachment'] as $attachment) {
|
||||
$this->appendPdf($mpdf,$attachment);
|
||||
}
|
||||
|
||||
$pdf = $mpdf->Output('车辆详情.pdf', 'S');
|
||||
$dir = runtime_path('pdf');
|
||||
if (!is_dir($dir)) mkdir($dir, 0777, true);
|
||||
$pdfName = '/invoice-' . date('YmdHis').'-'.$car['id'] . '.pdf';
|
||||
$path = $dir . $pdfName;
|
||||
$pdfName = 'invoice-' . date('YmdHis').'-'.$car['id'] . '.pdf';
|
||||
$path = $dir . '/' . $pdfName;
|
||||
file_put_contents($path, $pdf);
|
||||
|
||||
return $path;
|
||||
return $pdfName;
|
||||
}
|
||||
|
||||
public function appendPdf(Mpdf $mpdf, string $pdfPath)
|
||||
{
|
||||
$pageCount = $mpdf->SetSourceFile($pdfPath);
|
||||
for ($i = 1; $i <= $pageCount; $i++) {
|
||||
$tplId = $mpdf->ImportPage($i);
|
||||
$size = $mpdf->getTemplateSize($tplId);
|
||||
|
||||
$mpdf->AddPageByArray([
|
||||
'orientation' => $size['orientation'],
|
||||
'sheet-size' => [$size['width'], $size['height']]
|
||||
]);
|
||||
|
||||
$mpdf->UseTemplate($tplId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user