Ver Mensaje Individual
  #4 (permalink)  
Antiguo 09/07/2013, 12:55
Avatar de destor77
destor77
 
Fecha de Ingreso: noviembre-2004
Ubicación: Gálvez, Santa Fe, Argentina
Mensajes: 2.654
Antigüedad: 19 años, 5 meses
Puntos: 43
Respuesta: Integrar HTMLPDF en Codeigniter

no, es parte de un método privado de un controlador el código completo del método es:

Código PHP:
Ver original
  1. public function imprimir($email = null){
  2.         //$this->firephp->error($this->input->post());
  3.         /*echo"<pre>";
  4.         print_r($this->input->post());
  5.         echo"</pre>";exit();*/
  6.         //seteo las variables
  7.         $items = $this->input->post('items');
  8.         $desc_gral = $this->input->post('descuento_gral');
  9.         if($desc_gral !='' ){
  10.             $desc_gral = $this->input->post('descuento_gral');
  11.         }
  12.         else{
  13.             $desc_gral = 0;
  14.         }
  15.         $nro = $this->input->post('nro');
  16.         $subtotal = number_format($this->input->post('subtotal'),2,'.',' ');
  17.         $total = number_format($this->input->post('total'),2,'.',' ');
  18.         $empresa = $this->empresas->empresa_usuario($this->session->userdata('ba_id_empresa'));
  19.         $cliente = $this->clientes->searchPk($this->input->post('cliente_id'));
  20.         $entrega = $this->clientes_direcciones->searchPk($this->input->post('id_cliente_entrega'));
  21.         $pais_e = $this->pais->searchPk($entrega['pais_id']);
  22.         $facturacion = $this->clientes_direcciones->searchPk($this->input->post('id_cliente_facturacion'));
  23.         $pais_f = $this->pais->searchPk($facturacion['pais_id']);
  24.  
  25.         require_once(APPPATH.'libraries/html2pdf/html2pdf.class.php');
  26.         $html2pdf = new HTML2PDF('P', 'A4', 'es');
  27.         //$html = $this->load->view('presupuestos/imprimir',true);
  28.         //$this->firephp->info($html2pdf->getHtmlFromPage($html));
  29.  
  30.         $html = '<!DOCTYPE html>';
  31.         $html .= '<head>
  32.        <link href="'.base_url('assets/css/bootstrap.css').'" rel="stylesheet" type="text/css" />
  33. <link href="'.base_url('assets/css/styling.css').'" rel="stylesheet" type="text/css" />
  34. <link href="'.base_url('assets/css/stylesheet.css').'" rel="stylesheet" type="text/css" />
  35. <link href="'.base_url('assets/css/mystyles.css').'" rel="stylesheet" type="text/css" />';
  36.         $html .= '</head>
  37. <html lang="en">
  38.    <body class="smw">
  39.    <div class="content">
  40.    <div class="invoice">
  41.        <table style="border:none">
  42.    <tr>
  43.        <td colspan="3" style="border:none">
  44.            <h1 style="color: #42536D;font-size: 30px;line-height: 34px;margin: 0;">Presupuesto #'.$nro.'</h1>
  45.            <span style="color: #333333;display: block;font-size: 12px;font-weight: bold;line-height: 16px;margin-bottom: 50px;">Fecha: '.$this->input->post('fecha').'</span>
  46.        </td>
  47.    </tr>
  48.    <tr>
  49.        <td style="border:none">
  50.            <div class="span3">
  51.                <h4 style="border-bottom: 1px solid #DDDDDD;color: #42536D;font-size: 20px;line-height: 34px;">Domicilio Entrega</h4>
  52.                <address>
  53.                    <strong>'.$cliente['nombre'].'</strong><br>
  54.                    '.$entrega['direccion'].'<br>
  55.                    '.$entrega['ciudad'].', '.$entrega['provincia'].' '.$entrega['cp'].' '.$pais_e['nombre'].'<br>
  56.                    <span title="Phone">P:</span> '.$cliente['telefono'].'
  57.                </address>
  58.            </div>
  59.        </td>
  60.        <td style="border:none">
  61.            <div class="span3">
  62.                <h4 style="border-bottom: 1px solid #DDDDDD;color: #42536D;font-size: 20px;line-height: 34px;">Domicilio Facturaci&oacute;n</h4>
  63.                <address>
  64.                    <strong>'.$cliente['nombre'].'</strong><br>
  65.                    '.$facturacion['direccion'].'<br>
  66.                    '.$facturacion['ciudad'].', '.$facturacion['provincia'].' '.$facturacion['cp'].' '.$pais_f['nombre'].'<br>
  67.                    <span title="Phone">P:</span> '.$cliente['telefono'].'
  68.                </address>
  69.            </div>
  70.        </td>
  71.        <td style="border:none">
  72.            <div class="span3">
  73.                <h4 style="border-bottom: 1px solid #DDDDDD;color: #42536D;font-size: 20px;line-height: 34px;">Empresa</h4>
  74.                <address>
  75.                    <strong>'.$empresa[0]['nombre'].'</strong><br>
  76.                    '.$empresa[0]['direccion'].'<br>
  77.                    '.$empresa[0]['ciudad'].', '.$empresa[0]['provincia'].' ('.$empresa[0]['cp'].') '.$empresa[0]['pais'].'<br>
  78.                    <span>Tel:</span> '.$empresa[0]['telefono'].'<br/>
  79.                    Presupuest&oacute;: <strong>'.$this->session->userdata('ba_fullname').'</strong>
  80.                </address>
  81.            </div>
  82.        </td>
  83.    </tr>
  84.    <tr>
  85.        <td colspan="3" style="border:none"><h3 style="border-bottom: 1px solid #DDDDDD;color: #42536D;font-size: 20px;line-height: 34px;">Detalle</h3></td>
  86.    </tr>
  87.    <tr style="width:600px">
  88.        <td style="width:600px" colspan="3" style="border:none;width:600px;" >
  89.            <table style="width:600px" cellspacing="0" cellpadding="0">
  90.                <thead>
  91.                    <tr>
  92.                        <th width="20%">Familia</th>
  93.                        <th width="55%"></th>
  94.                        <th width="5%">Cantidad</th>
  95.                        <th width="10%">Descuento (%)</th>
  96.                        <th width="10%">Importe</th>
  97.                    </tr>
  98.                </thead>
  99.                <tbody>';
  100.         $total_item = count($items['item_id']);
  101.         for($i = 0; $i < $total_item; $i++){
  102.             $html .= '<tr>
  103.                            <td>'.$items['nombre'][$i].'</td>
  104.                            <td>'.$items['descripcion'][$i].'</td>
  105.                            <td>'.$items['cantidad'][$i].'</td>
  106.                            <td style"text-align:right">'.$items['descuento'][$i].'</td>
  107.                            <td style"text-align:right">'.number_format($items['precio'][$i],2,',','.').'</td>
  108.                        </tr>';
  109.         }
  110.         $html .= '
  111.                    <tr>
  112.                        <td colspan="3" style="border:none"></td>
  113.                        <td colspan="2" style="border:none">
  114.                            <p><strong><span>Subtotal:</span> <span>'.number_format($subtotal,2,',','.').'</span> &euro; </strong></p>
  115.                            <p><strong><span>Descuento Gral (%): '.$desc_gral.' %</span></strong></p>
  116.                            <p><strong><span>Total:</span> <span>'.number_format($total,2,',','.').'</span> &euro; </strong></p>
  117.                        </td>
  118.                    </tr>
  119.                </tbody>
  120.            </table>
  121.        </td>
  122.    </tr>
  123. </table>
  124. </div>
  125. </div>
  126.    </body>
  127. </html>';
  128.         if($email){
  129.             try
  130.             {
  131.                 $this->load->helper('date');
  132.                 $html2pdf->writeHTML($html);
  133.                 /*$content_PDF = $html2pdf->Output('', true);
  134.                 return $content_PDF;*/
  135.                 $nombre = APPPATH.'third_party/presupuesto_'.$this->session->userdata('ba_id_empresa').'_'.$cliente['clientes_id'].'_'.now();
  136.                 $html2pdf->Output($nombre.'.pdf', 'F');
  137.                 return $nombre;
  138.             }
  139.             catch(HTML2PDF_exception $e) {
  140.                 echo $e;
  141.                 exit;
  142.             }
  143.         }
  144.         else{
  145.             try
  146.             {
  147.                 $html2pdf->writeHTML($html);
  148.                 $html2pdf->Output('my_doc.pdf');
  149.             }
  150.             catch(HTML2PDF_exception $e) {
  151.                 echo $e;
  152.                 exit;
  153.             }
  154.         }
  155.  
  156.     }