生成pdf

This commit is contained in:
2026-01-09 15:03:30 +08:00
parent 620ef3fe3a
commit 4a1e243726
6 changed files with 105 additions and 9 deletions
+23 -3
View File
@@ -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);
}
}
}