想在PHP中将HTML转换为PDF。
$pdf = $quotingTool->createPdf($record->get('content'), $record-
>get('header'), $record->get('footer'), $fileName);
when use this createPdf() function then in this function use mpdf.
public function createPdf($content, $header = '', $footer = '', $name, $path
= 'storage/QuotingTool/', $styles = array(), $scripts = array(), $escapeForm = true)
{
$mpdf->SetHTMLHeader($header);
$mpdf->SetHTMLFooter($footer);
echo $content; //It shows proper designed html.
$mpdf->WriteHTML($content);
$fullFileName = $path . $name;
$mpdf->Output($fullFileName, 'I');
return $fullFileName;
}
$fileContent = '';
if(is_readable($pdf)) {
$fileContent = file_get_contents($pdf);
}
header('Content-type: application/pdf');
header('Pragma: public');
header('Cache-Control: private');
header('Content-Disposition: attachment; filename=' . html_entity_decode($fileName, ENT_QUOTES, vglobal('default_charset')));
header('Content-Description: PHP Generated Data');
echo $fileContent;
$content
中的此处显示正确的html,但转到$mpdf->WriteHTML($content)
时,生成pdf后,该设计未正确显示。内容放错了位置!