PHP to PDF probems

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: PHP to PDF probems

Post by seandisanti » Fri Apr 12, 2013 11:44 am

It looks like your calls to $dompdf -> load_html() are overwriting the same value. The easy solution is to concatenate your fields first. I'd say just at the beginning do:

Code: Select all

 
<?php
if($_POST &&!empty($_POST['content1'])) {
    $content = '';
    foreach ($_POST as $key => $value) {
        if ($key == 'name') {
            $name = $value;
        } else {
            $content .= $value;
        }
    }
    $img = "<img src=\"head.PNG\"/>";

    include_once('dompdf/dompdf_config.inc.php' );

    $dompdf = new DOMPDF();
    $dompdf->load_html($name);
    $dompdf->load_html($img);
    $dompdf->load_html($content);
    $dompdf->render();
    $dompdf->stream('Sample.pdf');
}
?>
<html>
    <body>
        <?php
        if (isset($error)) {
            echo $error;
        }
        ?>
        <form method="post" action="index1.php">
            <img src="head.PNG" name="img" width="200px" align="left">
            <p>Name<textarea name="name"></textarea></p>
            <p>Temporalis<textarea name="content1"></textarea></p>
            <p>Orbicularis occuli<textarea name="content2"></textarea></p>
            <p>Sternoclediomastoid<textarea name="content3"></textarea></p>
            <p>Orbicularis oris<textarea name="content4"></textarea></p>
            <p>Massefer<textarea name="content5"></textarea></p>
            <p>Platysma<textarea name="content6"></textarea></p>
            <input type="submit" name="submit" id="submit"/>

        </form>
    </body>
</html>

***edit*** minor change to code

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: PHP to PDF probems

Post by johnj » Sun Apr 14, 2013 7:37 pm

Did you try $dompdf->load_html($name.$img.$content); ?

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests