HTML转换为PDF在PHP中转换

时间:2018-08-16 14:09:15

标签: javascript php html css

想在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后,该设计未正确显示。内容放错了位置!

1 个答案:

答案 0 :(得分:1)

由于代码不足,我无法知道您正在使用哪个类 此外,您可以使用dompdf在此处阅读说明