使用PHP将HTML + CSS + JAVASCRIPT转换为PDF?

时间:2017-07-20 05:55:48

标签: javascript php html

直到现在我正在使用M_pdf将html和css页面转换为pdf,但现在我将javascript chrts包含在页面中。在下载时,图表不会加载到pdf文件中。通过哪种方法我将javacsript图表加载到pdf文件中。

1 个答案:

答案 0 :(得分:-2)

尝试使用DOMPDF库 https://github.com/dompdf/dompdf 在服务器上加载库后,可以将PHP文件和HTML文件分开以保存逻辑和结构。 例如 PHP(pdf.php):

    require $_SERVER['DOCUMENT_ROOT'] . '/pdf/dompdf/dompdf_config.inc.php';    
    $html = file_get_contents('pdf.html');
    $html = strtr($html, array(
        '#NAME#' => $name,
    ));    
    $dompdf = new DOMPDF();
    $dompdf->set_paper("A4", "landscape");
    $dompdf->load_html( 
        trim($html)
    );
    $dompdf->render();
    $dompdf->stream('PDFRender.pdf', array("Attachment" => false));
    return;

HTML(pdf.html)

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div class="korpus_descr">
          #NAME#
    </div> 
</body>
</html>

当然,请阅读并使用Documentation

相关问题