0

I am using dompdf library for downloading pdf format. The first created a pdf template in HTML format then a function used to call the dompdf library and viewing the function of download pdf. But it doesn't work CSS and HTML with tags. Below my code of the function of the controller

$this->load->library('Pdf');
    $id=$this->uri->segment(3);
     $data['title']='Invoice';
    $data['invoice_view']= $this->Invoice_Model->get_purchaseorder_by_id($id);
    $this->load->view('components/pdftemplate',$data);
    $html = $this->output->get_output();

     $dompdf=new DOMPDF();
     $dompdf->load_html($html);
     $dompdf->render();
     $dompdf->stream("invoice.pdf");enter code here

then created html template

<div class="block">
    <div class="row">
        <div class="col-md-6">
            <p>company Logo</p>
        </div>
        <div class="col-md-6"  style="float:left;color:red;">
            <p>Purchase Order</p>
        </div>
    </div>
    <div class="app-heading app-heading-small">                                
        <div class="title">
            <h5><?= $title;?></h5>
        </div>
    </div>
    <?php foreach($invoice_view as $inv):?>
     <div class="row">
            <div class="col-md-6">
               <div class="app-widget-informer">
                    <div class="title">To:<?= $inv->client_company_name;?></div>
                    <div class="tinyintval"><?= $inv->address;?></div>    
                    <div class="tinyintval"></div>                                                                             
                    <div class="tinyintval">Phone:<?= $inv->phone;?></div>
                    <div class="tinyintval">Email:<?= $inv->email;?></div>
               </div>
          </div>
            <div class="col-md-6">
                <div class="app-widget-informer">   
                    <div class="tinyintval">Po#:<?= $inv->invoice_id;?></div>                                        
                    <div class="tinyintval">Po Date:<?= $inv->issue_date;?></div>                                         
                </div>
            </div>                                
    </div>
                    <table class="table table-bordered" >
                        <thead>
                            <th>slno </th>
                            <th> Description</th>
                            <th>Unit Price</th>
                            <th>Quantity</th>
                            <th>Cost</th>
                            <th>Tax %</th>
                        </thead>
                       <tbody>
                       <?php foreach($inv->tableinvoice as $tabin):?>
                                <tr >
                                    <td>
                                    <?= $tabin->id; ?>
                                    </td>       
                                    <td>
                                    <?= $tabin->description; ?>
                                     </td>
                                    <td>
                                    <?= $tabin->quantity; ?>
                                    </td>
                                    <td>
                                    <?= $tabin->unitprice; ?>
                                    </td>
                                    <td>
                                    <?= $tabin->cost; ?>
                                    </td>
                                    <td>
                                    <?= $tabin->tax; ?>
                                    </td>
                               </tr>
                               <?php endforeach;?>      
                        </tbody>
                     </table>
                   <?php endforeach;?>
    </div>

but getting a text format doesn't work css and html styles.

Jeroen
  • 1,168
  • 1
  • 12
  • 24
Abdul Rafi
  • 43
  • 1
  • 9
  • Remove all white space in CSS and HTML and try it, hope it works. – Nimesh Patel Jan 19 '19 at 06:14
  • It's possible the issue has to do with how the CSS is referenced in the HTML produced by CI. It would help to see (at least part of) the value of the `$html` variable. – BrianS Feb 16 '19 at 17:36
  • Also, relevant information in this answer (even though the question is about CakePHP): https://stackoverflow.com/a/26029788/264628 – BrianS Feb 16 '19 at 17:36

0 Answers0