CodeIgniter Forums
domPDF not outputing data form db to PDF - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: domPDF not outputing data form db to PDF (/thread-56729.html)

Pages: 1 2


domPDF not outputing data form db to PDF - El Forum - 01-15-2013

[eluser]the_unforgiven[/eluser]
Hi guys,

Having a slight problem I'm hoping one or two of you can help me with.

When generating a PDF with domPDF it does not carry forward the $vars i have set but yet when print_r() or var_dump() is called the vars have data in them so not sure why this. Here is the code for generating the PDF

Code:
function pdf()
    {
       $this->load->library('parser');
       $id = $this->session->userdata('user_id');
              
       $data['orders'] = $this->invoice_model->getInvoiceID();
       $data['query'] = $this->account_model->getCurrent($id);
       $datestring = "%d/%m/%Y";
       $time = time();
       $in = mdate($datestring, $time);
       $gen = 'Invoice - '.$in;
      
       $filename  = $gen;
       $data['title']= $gen;
       $this->load->vars($data);
      
       // Create the PDF
       $html = $this->load->view('account/pdf', $data, TRUE);
       pdf_create($html, $filename, $data);
      
    }

View File for account/pdf
Code:
// Posted from <body> tag has there's a lot of inline styling which your guys arent interested in
<body class="pdf">
<div id="tpl-manage">


<div id="main">
  <div class="corners">
    
  </div>

  <div class="hidden clearfix"></div>
  
    
  
  <table id="header" class="default">
   <tr>
    <td id="logo">
     <img src="http://localhost/hb/assets/image/logo.png" alt="" />
    </td>
    <td id="address">
     The Company
                                         Address
    </td>
   </tr>  
  </table>

  <div id="separator">
   <hr />
  </div>

  <table id="info" class="default">
   <tr>
    <td id="to">
     <div class="c">
      
      <h1 class="title">Invoice</h1>
     </div>
  
     <p>
      <strong>To:</strong><br />
      &lt;?php echo $query['fullname']; ?&gt;<br />
      &lt;?php echo $query['address1']; ?&gt;<br />
      &lt;?php echo $query['address2']; ?&gt;<br />
      &lt;?php echo $query['town']; ?&gt;<br />
      &lt;?php echo $query['city']; ?&gt;<br />
      &lt;?php echo $query['postcode']; ?&gt;<br />
      &lt;?php echo $query['county']; ?&gt;<br />
     </p>
    </td>  
    <td id="ref">
     <h3>
      <strong>Invoice #:</strong> &lt;?php echo $orders['order_id']; ?&gt;<br />
      <strong>Date:</strong> &lt;?php echo $orders['order_date']; ?&gt;</h3>
    </td>
   </tr>  
  </table>


  
  <table id="body" class="default items">
   <tr class="header">
    <th class="col1">Item</th>
    <th class="col2">Description</th>
    <th class="col3" width="75">Unit Cost</th>
    <th class="col4" width="40">Quantity</th>
    <th class="col6" width="75">Cost (GBP)</th>
   </tr>
    <tbody id="items" class="itemslist">
     <tr id="invoice_items-395310" class="item handle">
      <td class="col1">

       <span>&lt;?php echo $orders['qty']; ?&gt;<br /></span>
      </td>
      <td class="col2">
       <span>&lt;?php echo $orders['item_ordered']; ?&gt;</span>
          
      </td>
      <td class="col3">
       <span>&pound;&lt;?php echo $orders['order_amount']; ?&gt;</span>
        
      </td>
      <td class="col4">
       <span>&lt;?php echo $orders['qty']; ?&gt;</span>
      </td>
      <td class="col6">
       <span>&pound;&lt;?php echo $orders['order_amount']; ?&gt;</span>
              
      </td>
     </tr>
        
    
    </tbody>
      
    <tr class="totals">
     <td colspan="5"><hr /></td>
    </tr>
    <tr class="totals">
     <td>Sub Total:</td>
     <td colspan="3">&nbsp;</td>
     <td>
      &pound;<span class="subtotal">&lt;?php echo $orders['order_amount']; ?&gt;</span>
     </td>
    </tr>
            <tr class="totals">
     <td>Total Amount (GBP):</td>
     <td colspan="3">&nbsp;</td>
     <td>
      &pound;<span class="total">&lt;?php echo $orders['order_amount']; ?&gt;</span>
     </td>
    </tr>
  
    <tr class="totals balance">
     <td><strong>Balance:</strong></td>
     <td colspan="3">&nbsp;</td>
     <td>
      <strong>&pound;<span class="balance">&lt;?php echo $orders['order_amount']; ?&gt;</span></strong>
     </td>
    </tr>
   </tbody>
  </table>

     <div id="due">
      &lt;!--<p>Payment due&nbsp;<strong>Dec 20th 2012</strong></p>--&gt;
      <p>Status:&nbsp;<strong>&lt;?php echo $orders['order_status']; ?&gt;</strong></p>
   </div>
  
  <div id="footer" class="block">
  
    
  </div>
  
   <center>
    <br class="clear" /><br /><hr />
    <p class="powered">Company Name</p>
   </center>
    
</div>

</div>
&lt;/body&gt;
&lt;/html&gt;
So has you can see all tallys up but doesn't generate in the PDF, if i view it in the browser all works fine, but not PDF, any idea's, suggestions greatly appreciated.
Thanks in advance! Smile


domPDF not outputing data form db to PDF - El Forum - 01-15-2013

[eluser]the_unforgiven[/eluser]
Anyone willing to help on this?


domPDF not outputing data form db to PDF - El Forum - 01-15-2013

[eluser]Otemu[/eluser]
Have you tried rendering the PDF outside codeigniter??

Using the class
Code:
&lt;?php
require_once("dompdf_config.inc.php");

$html =
  '&lt;html&gt;&lt;body>'.
  '<p>Put your html here, or generate it with your favourite '.
  'templating system.</p>'.
  '&lt;/body&gt;&lt;/html>';

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");

?&gt;



domPDF not outputing data form db to PDF - El Forum - 01-15-2013

[eluser]the_unforgiven[/eluser]
I have tried that well something similar yes with just html or text in and works fine ,but the data needs to come from the database has it's a pdf invoice!


domPDF not outputing data form db to PDF - El Forum - 01-15-2013

[eluser]Otemu[/eluser]
As a way to test, add the code above to your view and then load your dynamic data with in it. I would say test each dynamic data maybe one is causing conflict

I have never tried dompdf but since I am at work I cant try it for myself to see if it works.

&lt;?php
require_once("dompdf_config.inc.php");

$html =
'&lt;html&gt;&lt;body>'.
//load your codeigniter dynamic data here
'&lt;/body&gt;&lt;/html>';

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");

?&gt;


domPDF not outputing data form db to PDF - El Forum - 01-15-2013

[eluser]the_unforgiven[/eluser]
If you use CI you should know that loading like this require_once(“dompdf_config.inc.php”);

doesn't work!

But i have this al set up in a helper file

Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');


function pdf_create($html, $filename, $stream=TRUE)
{
    require_once("dompdf/dompdf_config.inc.php");
    
    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->set_paper("a4", "portrait" );
    $dompdf->render();
    $dompdf->stream($filename . ".pdf");
}



domPDF not outputing data form db to PDF - El Forum - 01-15-2013

[eluser]Sonny Nguyen[/eluser]
[quote author="the_unforgiven" date="1358263257"]If you use CI you should know that loading like this require_once(“dompdf_config.inc.php”);

doesn't work!

But i have this al set up in a helper file

Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');


function pdf_create($html, $filename, $stream=TRUE)
{
    require_once("dompdf/dompdf_config.inc.php");
    
    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->set_paper("a4", "portrait" );
    $dompdf->render();
    $dompdf->stream($filename . ".pdf");
}
[/quote]

about this line
require_once("dompdf/dompdf_config.inc.php");
you can make a config file in application/configs/dompdf.php for dompdf configurations and load It like as way that CI does
And move dompdf class to applications/library/ too


domPDF not outputing data form db to PDF - El Forum - 01-15-2013

[eluser]the_unforgiven[/eluser]
[quote author="Nguyen Minh Son" date="1358265298"][quote author="the_unforgiven" date="1358263257"]If you use CI you should know that loading like this require_once(“dompdf_config.inc.php”);

doesn't work!

But i have this al set up in a helper file

Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');


function pdf_create($html, $filename, $stream=TRUE)
{
    require_once("dompdf/dompdf_config.inc.php");
    
    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->set_paper("a4", "portrait" );
    $dompdf->render();
    $dompdf->stream($filename . ".pdf");
}
[/quote]

about this line
require_once("dompdf/dompdf_config.inc.php");
you can make a config file in application/configs/dompdf.php for dompdf configurations and load It like as way that CI does[/quote]

That's not the answer i was looking for but thanks all the same


domPDF not outputing data form db to PDF - El Forum - 01-15-2013

[eluser]Sonny Nguyen[/eluser]
please check
require_once("dompdf/dompdf_config.inc.php");
you sure that file, and pdf class were loaded? and turn php error_reporting to E_ALL for debug

Code:
function pdf()
    {
error_reporting(E_ALL); // add this code to your pdf function and run that for php message



domPDF not outputing data form db to PDF - El Forum - 01-15-2013

[eluser]the_unforgiven[/eluser]
Yes everything works if i just put text into the $html var it returns the pdf but not the $varibles set and i know thw $vars work has i have a view online invoice as a seperate function