简体   繁体   中英

Convert HTML to PDF Using dompdf

I currently have a page that generates HTML and fills in fields based on $_GET values from the previous PHP page.

I would like to convert the HTML of the page that I am on to a PDF and load it.

Can anybody help me out?

For some reason I get this as an error on page load:

Warning: require_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /var/www/html/asapweb/libs/full.php on line 2

Warning: require_once( http://kenai.asap.um.maine.edu/asapweb/libs/dompdf/dompdf_config.inc.php ): failed to open stream: no suitable wrapper could be found in /var/www/html/asapweb/libs/full.php on line 2

Fatal error: require_once(): Failed opening required ' http://kenai.asap.um.maine.edu/asapweb/libs/dompdf/dompdf_config.inc.php ' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/asapweb/libs/full.php on line 2

My page:

<?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");
?>

Thanks in advance!

You can only require and include files using the local server path, not the external HTTP path. (unless you have allow_url_include set to true )

Change this line

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

to

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

This is assuming the path is correct from your server's docroot.

Try the below code

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

Assuming that your dompdf_config.inc.php is available in following path.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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