使用dompdf将HTML转换为PDF

时间:2014-08-12 18:03:39

标签: php html dompdf

我目前有一个页面可以根据前一个PHP页面中的$_GET值生成HTML并填写字段。

我想将我所在页面的HTML转换为PDF并加载它。

有人可以帮帮我吗?

出于某种原因,我在页面加载时将其视为错误:

  

警告:require_once():http://在服务器中禁用了包装器   配置by allow_url_include = 0 in   第2行的/var/www/html/asapweb/libs/full.php

     

警告:   require_once(http://kenai.asap.um.maine.edu/asapweb/libs/dompdf/dompdf_config.inc.php):   无法打开流:没有找到合适的包装器   第2行的/var/www/html/asapweb/libs/full.php

     

致命错误:   require_once():需要打开失败   'http://kenai.asap.um.maine.edu/asapweb/libs/dompdf/dompdf_config.inc.php'   (include_path ='。:/ usr / share / pear:/ usr / share / php')in   第2行的/var/www/html/asapweb/libs/full.php

我的页面:

<?php
require_once("http://kenai.asap.um.maine.edu/asapweb/libs/dompdf/dompdf_config.inc.php");
ob_start();
?>

<html>
<body>
    <div style="width: 1000px; height: 1000px;">
        <h2><center>ASAP APPLICATION FORM</center></h2>
        <hr style="width: 700px;"><br>
        <div style="float: left; margin-left: 15%;">Date Submitted: <b><?php echo $_GET['dateSubmitted'] ?></b><br>
            <div style="margin-top: 50px;"><h3><i>PERSONAL INFORMATION</i></h3></div><br>

            <div style="margin-left: 50px">
                Name:&nbsp;&nbsp;&nbsp;<b><u><?php echo $_GET['firstName']." ".$_GET['lastName'] ?></u></b><br>
                Address:&nbsp;&nbsp;&nbsp;<b><u><?php echo $_GET['address'] ?></u></b><br>
                Phone:&nbsp;&nbsp;&nbsp;<b><u><?php echo $_GET['phone'] ?></u></b><br>
                Email:&nbsp;&nbsp;&nbsp;<b><u><?php echo $_GET['email'] ?></u></b><br>
            </div>
        </div>

        <div style="float: right; margin-right: 150px; margin-top: 50px;"><h3><i>ACADEMIC INFORMATION</i></h3><br>
            <div style="margin-top: 5px; margin-left: 50px;">
                Major:&nbsp;&nbsp;&nbsp;<b><u><?php echo $_GET['major'] ?></u></b><br>
                Expected Graduation Year:&nbsp;&nbsp;&nbsp;<b><u><?php echo $_GET['gradDate'] ?></u></b><br>
                Relevant work?:&nbsp;&nbsp;&nbsp;<b><u><?php echo ucfirst($_GET['work']) ?></u></b><br>
            </div>
        </div>

        <div style="margin-top: 250px; margin-left: 39%;"><h3><i>TELL US MORE ABOUT YOU</i></h3><br>

            <div style="margin-left: -200px; margin-top: 20px;"><b>Position(s) interested in:</b>&nbsp;&nbsp;&nbsp;<?php echo $_GET['positions'] ?></div>
            <br>
            <div style="margin-left: -200px; margin-bottom: 50px;"><b>Do you have work-study?</b>&nbsp;&nbsp;&nbsp;<?php echo $_GET['workStudy'] ?></div>

            <div style="float: right; margin-right: 100px;">
                <span style="margin-left: 70px;">Describe your creative strengths:</span><br>
                <textarea rows="10" cols="40" style="margin-top: 20px;"><?php echo $_GET['previousExperience'] ?></textarea>
            </div>
            <div style="margin-left: -240px;">
                <span style="margin-left: 30px;">Briefly describe your previous work experience:</span><br>
                <textarea rows="10" cols="40" style="margin-top: 20px;"><?php echo $_GET['creativeStrengths'] ?></textarea>
            </div>

            <br>

            <div style="float: right; margin-right: 100px;">
                <span style="margin-left: 100px;">What are your skills?:</span><br>
                <textarea rows="10" cols="40" style="margin-top: 20px;"><?php echo $_GET['skills'] ?></textarea>
            </div>
            <div style="margin-left: -240px;">
                <span style="margin-left: 50px;">What interests you about this position?:</span><br>
                <textarea rows="10" cols="40" style="margin-top: 20px;"><?php echo $_GET['interests'] ?></textarea>
            </div>
        </div><br>
    </div>
</body>
</html>

<?php
$html = ob_get_clean();
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
?>

提前致谢!

2 个答案:

答案 0 :(得分:1)

您只能使用本地服务器路径的requireinclude文件,外部HTTP路径。 (除非您将allow_url_include设置为true

更改此行

 require_once("http://kenai.asap.um.maine.edu/asapweb/libs/dompdf/dompdf_config.inc.php");

 require_once($_SERVER['DOCUMENT_ROOT']."/asapweb/libs/dompdf/dompdf_config.inc.php");

这假设您的服务器的docroot路径是正确的。

答案 1 :(得分:1)

尝试以下代码

include("dompdf/dompdf_config.inc.php");

假设您的dompdf_config.inc.php在以下路径中可用。

/var/www/html/asapweb/dompdf/dompdf_config.inc.php