Help using latest dompdf version

129 views
Skip to first unread message

Matthew Webley

unread,
Jul 10, 2013, 7:33:13 AM7/10/13
to dom...@googlegroups.com
Hi all.
I have tried following the beginner tutorials to get me up and running with dompdf.. But am having issues.
I can get the basic example working where html is put into a php variable and prints out a basic pdf but need to go further.
I am creating a webpage that is chosen dynamically... You can see it here, once the selection is made I want dompdf to create a pdf on the fly.
How can I get the resulting php page to create a pdf of itself?
I have followed some of the tutorials and am getting errors.


Any help greatly appreciated.
Thanks.

BrianS

unread,
Jul 10, 2013, 10:35:09 AM7/10/13
to dom...@googlegroups.com
If the page is built from pre-generated components you can pass the information necessary to regenerate it back to the server and rebuild the page in PHP. Another method is to capture the HTML and send it back to the server.

But right now we don't know what you have tried or what errors you are encountering. So a bit more detail would help resolve your issues.

Matthew Webley

unread,
Aug 30, 2013, 1:17:12 PM8/30/13
to dom...@googlegroups.com
Hi.
Thanks for your reply.  So I have gone back to version 0.5.1 and am having more luck.
The PDF is starting to render.. But stops when I add too many <br /> s in the html.
I have a table which at the top which renders okay. Have tried another table below this and a div. But getting the same issue.
If I use debug mode, the error i get is - Catchable fatal error: Object of class DOMElement could not be converted to string in C:\xampp\htdocs\tradis\include\frame.cls.php on line 578
I have an index.php page which captures information and posts to a pdf.php page. In the pdf.php page I

require_once("dompdf_config.inc.php");
php ob_start();

Here some of the content is dynamically generated - text and some images.

At the end of the html I have

<?php
file_put_contents('newtest.html', ob_get_contents());
    $dompdf = new DOMPDF();
    $dompdf->load_html(file_get_contents('newtest.html'));
    $dompdf->render();
    $dompdf->stream("mytest.pdf");
?>

Can you advise if this is correct?

Thank you again.

BrianS

unread,
Sep 1, 2013, 1:54:09 PM9/1/13
to dom...@googlegroups.com
The error you see is a problem in the debugging code, not anything related to your document. You should update to 0.6.0 for best results. Your code looks fine. Are the BR's inside a table? Currently dompdf is unable to work with table cells larger than the page size. Otherwise it would help to see your HTML.

Matthew Webley

unread,
Sep 1, 2013, 4:24:13 PM9/1/13
to dom...@googlegroups.com
OK. will try updating now.
Below is my code. just getting a bunch of variables at the start......
Then the code is pretty standard.

Any help would be greatly appreciated!  Thankyou.

<?php
$array = ($_GET ['hidden_second']);
foreach ($array as $details)
{
$contacts = explode(",", $details);
}
$contact_name = $contacts[0];
$contact_company = $contacts[1];
$contact_email = $contacts[2];
$contact_number = $contacts[3];
$contact_project = $contacts[4];

$input_array=($_GET['hidden']);
foreach ($input_array as $arrays)
{
$bits = explode(",", $arrays);
}
$type = $bits[0];
if ($type == 'Wall'){
$walllist = array("Timber Cladding on battens<img src='img/a.jpg'>","Ventilated Cavity<img src='img/b.jpg'>" );

        $material = $bits[1];
        $size = $bits[3];
        $depth = "Stud";
            if ($material == 'Brick') {
        $mainimage = "<img src='img/wallbrick.jpg' alt='Brick Wall' />";
                switch ($size) {
    case "200mm":
        $uvalue=0.17;
        $csfh='Level 4';
        break;
    case "220mm":
        $uvalue=0.16;
        $csfh='Level 4';
        break;
    case "240mm":
        $uvalue=0.15;
        $csfh='Level 4';
        break;
    case "280mm":
        $uvalue=0.13;
        $csfh='Level 5';
        break;
    case "300mm":
        $uvalue=0.12;
        $csfh='Level 5';
        break;
    case "360mm":
        $uvalue=0.11;
        $csfh='Level 6';
        break;
    case "400mm":
        $uvalue=0.10;
        $csfh='Level 6';
        break;
            }
        }else {
        $mainimage = "<img src='img/walltimber.jpg' alt='Wall with Timber' />";
        switch ($size) {
    case "200mm":
        $uvalue=0.19;
        $csfh='Level 4';
        break;
    case "220mm":
        $uvalue=0.17;
        $csfh='Level 4';
        break;
    case "240mm":
        $uvalue=0.16;
        $csfh='Level 4';
        break;
    case "280mm":
        $uvalue=0.14;
        $csfh='Level 5';
        break;
    case "300mm":
        $uvalue=0.13;
        $csfh='Level 5';
        break;
    case "360mm":
        $uvalue=0.11;
        $csfh='Level 6';
        break;
    case "400mm":
        $uvalue=0.10;
        $csfh='Level 6';
        break;   
            }
        }
}
        elseif ($type == 'Roof'){
        $walllist = array("<p>Slates / Tyles</p><img src='img/a.jpg' alt='guide' />", "<p>Warmcel</p><img src='img/b.jpg' alt='guide' />", "<p>Services batten</p><img src='img/c.jpg' alt='guide' />", "<p>Plaster board</p><img src='img/d.jpg' alt='guide' />", "<p>Timber board (6mm)</p><img src='img/e.jpg' alt='guide' />", "<p>Vapour control layer</p><img src='img/f.jpg' alt='guide' />", "<p>Battens</p><img src='img/g.jpg' alt='guide' />", "<p>Rafters</p><img src='img/h.jpg' alt='guide' />", "<p>Counter battens (50mm) depth</p><img src='img/i.jpg' alt='guide' />", "<p>Roof tile / breather membrane <br />with small elongation value</p><img src='img/j.jpg' alt='guide' />" );
            $size = $bits[1];
            $mainimage = "<img src='img/roof.jpg' alt='roog image' />";
            $depth = "Rafter";
            switch ($size) {
    case "200mm":
        $uvalue=0.18;
        $csfh='Level 4';
        break;
    case "220mm":
        $uvalue=0.16;
        $csfh='Level 4';
        break;
    case "240mm":
        $uvalue=0.15;
        $csfh='Level 4';
        break;
    case "280mm":
        $uvalue=0.13;
        $csfh='Level 5';
        break;
    case "300mm":
        $uvalue=0.12;
        $csfh='Level 5';
        break;
    case "360mm":
        $uvalue=0.10;
        $csfh='Level 6';
        break;
    case "400mm":
        $uvalue=0.10;
        $csfh='Level 6';
        break;
            }
        }
        else {
            $walllist = array("<p>22mm Chipboard / Weyroc</p><img src='img/a.jpg' alt='guide' />", "<p>RB400 membrane</p><img src='img/b.jpg' alt='guide' />", "<p>I-Beam</p><img src='img/c.jpg' alt='guide' />", "<p>Warmcel</p><img src='img/d.jpg' alt='guide' />", "<p>Timberline</p><img src='img/e.jpg' alt='guide' />", "<p>Damp proof membrane</p><img src='img/f.jpg' alt='guide' />", "<p>Concrete</p><img src='img/g.jpg' alt='guide' />" );
            $floortype = $bits[1];
            $depth = "Joist";
            if ($floortype == 'Ground') {
        $mainimage = "<img src='img/floorconcrete.jpg' alt='Concrete Ground' /    >";
        $floorsize = $bits[4];       
            if ($floorsize == 'Floor Size: 7 x 7' || 'Floor Size: 8 x 8') {
            $size = $bits[6];
                switch ($size) {
    case "200mm":
        $uvalue=0.16;
        $csfh='Level 4';
        break;
    case "220mm":
        $uvalue=0.15;
        $csfh='Level 4';
        break;
    case "240mm":
        $uvalue=0.14;
        $csfh='Level 4';
        break;
    case "280mm":
        $uvalue=0.12;
        $csfh='Level 5';
        break;
    case "300mm":
        $uvalue=0.11;
        $csfh='Level 5';
        break;
    case "360mm":
        $uvalue=0.10;
        $csfh='Level 6';
        break;
            }   
                }else if ($floorsize == 'Floor Size: 9 x 9' || 'Floor Size: 10 x 10') {
 $size = $bits[6];
                switch ($size) {
    case "200mm":
        $uvalue=0.15;
        $csfh='Level 4';
        break;
    case "220mm":
        $uvalue=0.14;
        $csfh='Level 4';
        break;
    case "240mm":
        $uvalue=0.13;
        $csfh='Level 4';
        break;
    case "280mm":
        $uvalue=0.12;
        $csfh='Level 5';
        break;
    case "300mm":
        $uvalue=0.11;
        $csfh='Level 5';
        break;
    case "360mm":
        $uvalue=0.10;
        $csfh='Level 6';
        break;
            }       
                }           
        }else {
        $mainimage = "<img src='img/floorsuspended.jpg' alt='Suspended Floor' />";
        $floorsize = $bits[4];       
               
            if ($floorsize == 'Floor Size: 7 x 7' || 'Floor Size: 8 x 8') {
               
 $size = $bits[6];
                switch ($size) {
    case "200mm":
        $uvalue=0.16;
        $csfh='Level 4';
        break;
    case "220mm":
        $uvalue=0.15;
        $csfh='Level 4';
        break;
    case "240mm":
        $uvalue=0.14;
        $csfh='Level 4';
        break;
    case "280mm":
        $uvalue=0.12;
        $csfh='Level 5';
        break;
    case "300mm":
        $uvalue=0.11;
        $csfh='Level 5';
        break;
    case "360mm":
        $uvalue=0.10;
        $csfh='Level 6';
        break;
            }
                }else if ($floorsize == 'Floor Size: 9 x 9' || 'Floor Size: 10 x 10') {
        $size = $bits[6];
                switch ($size) {
    case "200mm":
        $uvalue=0.15;
        $csfh='Level 4';
        break;
    case "220mm":
        $uvalue=0.14;
        $csfh='Level 4';
        break;
    case "240mm":
        $uvalue=0.13;
        $csfh='Level 4';
        break;
    case "280mm":
        $uvalue=0.12;
        $csfh='Level 5';
        break;
    case "300mm":
        $uvalue=0.11;
        $csfh='Level 5';
        break;
    case "360mm":
        $uvalue=0.10;
        $csfh='Level 6';
        break;
            }       
        }           
        }   
    }
?>
<?php
require_once("dompdf/dompdf_config.inc.php");
?>
<html>
<head>
<title>Tradis - Build your system</title>
</head>
<body>
<div class="left">
<table border="1">
<tr>
<th>Header</th>
</tr>
<tr>
<td rowspan="7"><img src="top.jpg"></td><td colspan="4"><?php print $contact_project; ?></td>
</tr>
<tr>
<td colspan="4"><?php print $contact_company; ?></td>
</tr>
<tr>
<td colspan="4">Name:  <?php print $contact_name; ?></td>
</tr>
<tr>
<td colspan="2">Tel:<?php print $contact_number; ?></td><td colspan="2">Email: <?php print $contact_email;?></td>
</tr>
<tr>
<td>'U' Value</td><td>Can help to meet</td><td>Stud Depth</td><td>Overall wall depth</td>
</tr>
<tr>
<td>test</td><td>test</td><td>test</td><td>test</td>
</tr>
<tr>
<td>test</td><td>test</td><td>test</td><td>test</td>
</tr>
<tr>
<td>
<p>hello</p><img src="a.jpg"><br>
</td>
<td>
<p>hello</p><img src="a.jpg"><br>
</td>
<td id="mainimage" colspan="4">
</td>
</tr>
</table>
</html>

<?php
file_put_contents('newtest.html', ob_get_contents());
    $dompdf = new DOMPDF();
    $dompdf->load_html(file_get_contents('newtest.html'));
    $dompdf->render();
    $dompdf->stream("please.pdf");
?>

Matthew Webley

unread,
Sep 1, 2013, 5:37:08 PM9/1/13
to dom...@googlegroups.com
Not even this works with dompof v 0.6.0

<?php ob_start(); ?>

<html>
<head>
<title>Tradis - Build your system</title>
</head>
<body>
<div class="left">
<table border="1">
<tr>
<td>hello</td>
</tr>
</table>
</body>

</html>
<?php
file_put_contents('newtest.html', ob_get_contents());
require_once("dompdf/dompdf_config.inc.php");

$dompdf = new DOMPDF();
$dompdf->load_html(file_get_contents('newtest.html'));
$dompdf->render();
$dompdf->stream("mypdf.pdf");
?>

Anton Klein

unread,
Sep 3, 2013, 7:03:21 AM9/3/13
to dom...@googlegroups.com
Adding ob_end_clean(); after your file_put_contents line makes it work. Without it the html is at the start of your pdf output, rendering it invalid. Besides that you also need to close the <div>, but dompdf is handling this less valid html well.

Op zondag 1 september 2013 23:37:08 UTC+2 schreef Matthew Webley:
Reply all
Reply to author
Forward
0 new messages