Welcome Guest, Not a member yet? Register   Sign In
DOMpdf Documentation with Code Igniter
#1

[eluser]kevinprince[/eluser]
Im trying to do some stuff in Dom PDF and can get data into a pdf and start formatting. The problem is I cant fiqure out how to use the DOMpdf commands, eg how do you after 20 rows go to a new page?

Be really handy if we could all working on getting the wiki page a little more up to date for this as a lot of us need to use DOMpdf in our projects.
#2

[eluser]Crimp[/eluser]
As I recall, this is done with CSS: page-break: after. (DOMpdf is not exactly a dream when it comes to complex layouts). One solution may be to loop the results and insert a CSS div with page break applied after each 20. Keep in mind that DOMpdf does two passes: one for PHP and the second pass for DOMpdf commands. This allows you to execute all PHP and then act on the results with DOMpdf.
#3

[eluser]kevinprince[/eluser]
Here is my code for the view, ive tried the page break css a few ways this way it just makes a few blank sheets.

Help appreciated!

Code:
<html>
<style type="text/css">

body {
    margin: 0.5in;
}
h1, h2, h3, h4, h5, h6, li, blockquote, p, th, td {
    font-family: Helvetica, Arial, Verdana, sans-serif; /*Trebuchet MS,*/
}
h1, h2, h3, h4 {
    color: #5E88B6;
    font-weight: normal;
}
h4, h5, h6 {
    color: #5E88B6;
}
h2 {
    margin: 0 auto auto auto;
    font-size: x-large;
}
li, blockquote, p, th, td {
    font-size: 80%;
}
ul {
    list-style: url(/img/bullet.gif) none;
}
table {
    width:95%;
    border-top:1px solid #e5eff8;
    border-right:1px solid #e5eff8;
    margin: 0 auto;
    border-collapse:collapse;
    font-size: 14px;
    }
tr.odd td    {
    background:#f7fbff
    }
tr.odd .column1    {
    background:#f4f9fe;
    }    
.column1    {
    background:#D8DFEA;
    }
td {
    color:#444;
    border-bottom:1px solid #e5eff8;
    border-left:1px solid #e5eff8;
    padding: 2px;
    text-align:left;
    }                
th {
    font-weight:normal;
    color: #3B5998;
    text-align:left;
    border-bottom: 1px solid #e5eff8;
    border-left:1px solid #e5eff8;
    padding: 2px 2px 2px 5px;
    }                            
thead th {
    background:#D8DFEA;
    text-align:left;
    font:bold 11px "Century Gothic","Trebuchet MS",Arial,Helvetica,sans-serif;
    color:#3B5998;
    }    
tfoot th {
    text-align:center;
    background:#f4f9fe;
    }    
tfoot th strong {
    font:bold 01px "Century Gothic","Trebuchet MS",Arial,Helvetica,sans-serif;
    margin: 0;
    color:#66a3d3;
        }        
tfoot th em {
    color:#f03b58;
    font-weight: bold;
    font-size: 10px;
    font-style: normal;
    }    

#footer {
    border-top: 1px solid #CCC;
    text-align: right;
}

P.breakhere {page-break-after: always}
</style>
<body>
    <h3>Call List : &lt;?=$title;?&gt;</h3>
    <table width="100%" cellpadding="0" cellspacing="0" bordercolor="000" style="font:Arial, Helvetica, sans-serif">
   <tr>
    <td width="50%" bgcolor="#CCCCCC"><b>Name</b></td>
    <td width="50%" bgcolor="#CCCCCC"><b>Number</b></td>
   </tr>
   &lt;?php $i = 0; foreach($contacts as $item) { $i++?&gt;
  <tr>
    <td>[&lt;?php echo $i; ?&gt;] - &lt;?php echo $item['fname'];?&gt; &lt;?php echo $item['sname'];?&gt;</td>
    <td>&lt;?php echo $item['phone'];?&gt; &lt;? echo $item['mobile'];?&gt;</td>
  </tr>
  &lt;?php if ($i == "20") { echo "<p STYLE='page-break-after: always'></p>"; $i=0; }?&gt;
  &lt;?php };?&gt;
</table>
&lt;/body&gt;
&lt;/html&gt;
#4

[eluser]Crimp[/eluser]
You just have to experiment with the options and hack your way. I have done quite complex things with it -- but they were not always logical in terms of how one would think they should be solved at the outset. Glancing at the code, you insert a block paragraph in the middle of the table and expect it to resume with rows on the next page. I suspect DOMpdf does not like that. The HTML needs to be well formed. Since it only applies to block level elements, you'd have to start and end a table for each page. How about going for the second pass and something like new_page() instead? I always did headers and footers etc. on a second pass because it was more reliable.
#5

[eluser]kevinprince[/eluser]
Bit busy with other work today, but will have a go tonight on this and let you know.

I will try and update the wiki too with more instructions.
#6

[eluser]treworld[/eluser]
Make sure your $contacts array is actually spitting out data. Do a print_r on that array first before you send it to domPdf.
#7

[eluser]kevinprince[/eluser]
Read the thread first...
#8

[eluser]treworld[/eluser]
"page-break-after: always" is correct. Try using <DIV STYLE="page-break-after: always"></DIV>. Again, if you still get blank pages, check your array's data.
#9

[eluser]kevinprince[/eluser]
It wasnt the array which was broken, the template code was, basically as Crimp said it wouldn't work within the table. Ive corrected it now and it works fine.

If the fault was in the data array then I wouldn't of got any data and would of had error messages.




Theme © iAndrew 2016 - Forum software by © MyBB