繁体   English   中英

使用dompdf将HTML转换为PDF

[英]Convert HTML to PDF Using dompdf

我目前有一个页面,该页面生成HTML,并基于上一个PHP页面中的$_GET值填写字段。

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

有人可以帮我吗?

由于某种原因,我将此作为页面加载时的错误得到:

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

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

致命错误:require_once():无法打开所需的' http://kenai.asap.um.maine.edu/asapweb/libs/dompdf/dompdf_config.inc.php'(include_path ='。:/ usr / share / pear:第2行的/var/www/html/asapweb/libs/full.php中的/ usr / share / 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");
?>

提前致谢!

您只能使用本地服务器路径而不是外部HTTP路径来requireinclude文件。 (除非您将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是正确的。

试试下面的代码

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM