Foros del Web » Programando para Internet » PHP » Frameworks y PHP orientado a objetos »

Integrar HTMLPDF en Codeigniter

Estas en el tema de Integrar HTMLPDF en Codeigniter en el foro de Frameworks y PHP orientado a objetos en Foros del Web. Hola amigos antes de entra a utilizar codeigniter utilice dompdf pero notaba que el performance era algo lento entonces me tope con HTML2PDF y sin ...
  #1 (permalink)  
Antiguo 08/07/2013, 12:31
Avatar de chalchis  
Fecha de Ingreso: julio-2003
Mensajes: 1.773
Antigüedad: 20 años, 9 meses
Puntos: 21
Pregunta Integrar HTMLPDF en Codeigniter

Hola amigos antes de entra a utilizar codeigniter utilice dompdf pero notaba que el performance era algo lento entonces me tope con HTML2PDF y sin dunda me gusto mas que dompdf
mi problema es como puedo integrar esta libreria como una libria en codeigniter
por el momento lo he logrado asi siguiendo el post de un usuario

http://stackoverflow.com/questions/1...33073#17533073

pero habra una mejor forma de intergrarlo como libreria saludos
espero sus comentarios
__________________
gerardo
  #2 (permalink)  
Antiguo 09/07/2013, 12:23
Avatar de 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

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

salu2
  #3 (permalink)  
Antiguo 09/07/2013, 12:27
Avatar de chalchis  
Fecha de Ingreso: julio-2003
Mensajes: 1.773
Antigüedad: 20 años, 9 meses
Puntos: 21
Respuesta: Integrar HTMLPDF en Codeigniter

mm me imagino que lo estas incluyendo directamente en la vista???
__________________
gerardo
  #4 (permalink)  
Antiguo 09/07/2013, 12:55
Avatar de 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.     }
  #5 (permalink)  
Antiguo 11/07/2013, 14:16
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 9 meses
Puntos: 379
Respuesta: Integrar HTMLPDF en Codeigniter

Creo que esta liga te puede ayudar:
[URL="http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html"]http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html[/URL]
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.

Etiquetas: codeigniter, integrar
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:52.