problema comn TCPDF

1,063 views
Skip to first unread message

novata

unread,
Dec 1, 2012, 2:35:36 AM12/1/12
to cakep...@googlegroups.com
Tengo el siguiente problema, cree un pdf utilizando TCDPF, si en output tomo como opcion el descargar el archivo (D) este se descarga sin ningun problema y me muestra todo el contenido correctamente, PERO si en cambio en output tengo como opcion que el pdf se visualice en el navegador (I), este no lo muestra, y solo muestra caracteres especiales , algo como esto: 
probe con todos los tipos de codificacion en el archivo de la vista del pdf, y nada.

alguien sabe a que se pueda deber el error.

(no tengo problemas en mi navegador para visualizar otro tipo de archivos PDF disponibles en sitios web)

gracias por su ayuda.












Jordan Mendieta

unread,
Dec 2, 2012, 9:02:27 AM12/2/12
to cakep...@googlegroups.com
Yo tuve muchos problemas con es clase así que me pasé a mPDF y  todo resuelto


El 1 de diciembre de 2012 02:35, novata <soli...@hotmail.com> escribió:
Tengo el siguiente problema, cree un pdf utilizando TCDPF, si en output tomo como opcion el descargar el archivo (D) este se descarga sin ningun problema y me muestra todo el contenido correctamente, PERO si en cambio en output tengo como opcion que el pdf se visualice en el navegador (I), este no lo muestra, y solo muestra caracteres especiales , algo como esto: 
probe con todos los tipos de codificacion en el archivo de la vista del pdf, y nada.

alguien sabe a que se pueda deber el error.

(no tengo problemas en mi navegador para visualizar otro tipo de archivos PDF disponibles en sitios web)

gracias por su ayuda.












--
Has recibido este mensaje porque estás suscrito al grupo "CakePHP en Español" de Grupos de Google.
Para ver este debate en la Web, visita https://groups.google.com/d/msg/cakephp-esp/-/EqemxD_EXEEJ.
Para publicar una entrada en este grupo, envía un correo electrónico a cakep...@googlegroups.com.
Para anular tu suscripción a este grupo, envía un correo electrónico a cakephp-esp...@googlegroups.com
Para tener acceso a más opciones, visita el grupo en http://groups.google.com/group/cakephp-esp?hl=es.

Aland Laines

unread,
Dec 3, 2012, 9:14:38 AM12/3/12
to cakep...@googlegroups.com
seria de ayuda ver el layout de pdf y la vista que estas generando..

Aland Laines Calonge
Twitter: @lainessolutions

novata

unread,
Dec 3, 2012, 9:38:43 PM12/3/12
to cakep...@googlegroups.com

layout:

pdf.ctp-->

<?php 
header("Content-type: application/pdf"); 
echo $content_for_layout; 
?>


Esta vista la saque de un ejemplo de internet, no es el que utilizaré pero de todas formas acá la dejo.


<?php


App::import('Vendor','tcpdf');
$tcpdf = new TCPDF();
$textfont = 'freesans';
$tcpdf->SetCreator(PDF_CREATOR);
$tcpdf->SetAuthor("autor");
$tcpdf->SetTitle("Título");
$tcpdf->SetSubject("Tutorial TCPDF en cakePHP");
$tcpdf->SetKeywords("TCPDF, PDF, cakePHP, ejemplo");
$tcpdf->setPrintHeader(false);
$tcpdf->setPrintFooter(false);
$tcpdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$tcpdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$tcpdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$tcpdf->setLanguageArray($l);
$tcpdf->AliasNbPages();
$tcpdf->AddPage();
$tcpdf->SetFont("freesans", "BI", 20);
$tcpdf->Cell(0,10,"Hola mundo",1,1,'C');
$tcpdf->Output("ejemplo.pdf", I");

?> 


la funcion en el controlador::


function pdf()
{
      Configure::write('debug',0);
      $this->layout = 'pdf'; 
      $this->render();
}



Gracias por la ayuda.

Miguel Leugim

unread,
Dec 3, 2012, 11:23:06 PM12/3/12
to cakep...@googlegroups.com
Hola como te aconseja Jordan,
usa mPDF , mucho mas fácil y rápido, ademas de poder usar mas html y
css en las opciones.

saludos
> --
> Has recibido este mensaje porque estás suscrito al grupo "CakePHP en
> Español" de Grupos de Google.
> Para ver este debate en la Web, visita
> https://groups.google.com/d/msg/cakephp-esp/-/bD3j_KQlCiIJ.

Aland Laines

unread,
Dec 4, 2012, 9:29:57 AM12/4/12
to cakep...@googlegroups.com
Hola Novata, yo no tengo ningun problema usando el tcpdf, lo uso para en un sistema de emision de fotocheck, y todo va bien, lo que si he notado que es disitinta la sintaxis que usas a la que tengo yo, mi version de TCPDF  es la Version: 5.9.157, por ejemplo uso esto:

    // create new PDF document
    $tcpdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
   
    //$fontname = $tcpdf->addTTFfont('tmp/ariblk.ttf', 'TrueTypeUnicode', '', 32);
    $tcpdf->AddFont('arialnb','BI', 20,'','false');
    $tcpdf->AddFont('ariblk','BI', 20,'','false');
   
    // set document information
    $tcpdf->SetCreator(PDF_CREATOR);
    $tcpdf->SetAuthor('Aland Laines');
    $tcpdf->SetTitle('Carnet Autoridad Pol�tica');
    $tcpdf->SetSubject('TCPDF Tutorial');
    $tcpdf->SetKeywords('fotocheck, DGGI, gobernador');
   
    // set header and footer fonts
    $tcpdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
   
    // set default monospaced font
    $tcpdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
   
    //set margins
    $tcpdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $tcpdf->SetHeaderMargin(0);
    $tcpdf->SetFooterMargin(0);
   
    // remove default footer
    $tcpdf->setPrintFooter(false);
   
    //set auto page breaks
    $tcpdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
   
    //set image scale factor
    $tcpdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
   
    //set some language-dependent strings
    //$tcpdf->setLanguageArray($l);
   
    // ---------------------------------------------------------
   
    // set font
    $tcpdf->SetFont('times', '', 6);
   
    // --- example with background set on page ---
   
    // remove default header
    $tcpdf->setPrintHeader(false);
   
    // add a page
    //$tcpdf->AddPage();
    $tcpdf->AddPage('L', 'CARNET_DGGI');
   
    // -- set new background ---
   
    // get the current page break margin
    $bMargin = $tcpdf->getBreakMargin();
    // get current auto-page-break mode
    $auto_page_break = $tcpdf->getAutoPageBreak();
    // disable auto-page-break
    $tcpdf->SetAutoPageBreak(false, 0);
    // set background image
    $img_file = '../files/base/tira.jpg';
    $tcpdf->Image($img_file, 0, 0, 86, 54, '', '', '', false, 300, '', false, false, 0);
    $tcpdf->SetFont('ariblk', '', 6);
    $tcpdf->SetXY(35,13);
    $html = '<span style="color:black;">R.D. N&deg; '.$resolucion.'-'.$fnomb.'-1501</span>';
    $tcpdf->writeHTML($html, true, false, true, false, '');
    //$tcpdf->Write(0,'R.D. N� 9818-2011-1501');
    $tcpdf->SetFont('arialnb', 'B', 6);
    $tcpdf->SetXY(45,17);
    //$tcpdf->Write(0,$tipo);
    $html = '<span>'.$tipo.'</span>';
    $tcpdf->writeHTML($html, true, false, true, false, '');
    $tcpdf->SetXY(44,19.5);
    $tcpdf->Write(0,$distrito);
    $tcpdf->SetXY(44,22);
    $tcpdf->Write(0,$provincia);
    $tcpdf->SetXY(44,24.5);
    $tcpdf->Write(0,$region);
    //Foto
    $tcpdf->Image('../../Publicacion/fotos/'.$dni.'.jpg', 5, 14.5, 22, 25.5, '', '', '', false, 72, '', false, false, array('LTRB' => array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0))));
    // Pie de Foto
    $tcpdf->SetFont('arialn', 'B', 7);
    $tcpdf->SetXY(1,42);
    $tcpdf->Cell(30.5, 0, $apePat.' '.$apeMat, 0, 1, 'C', 0, '', 1);
    $tcpdf->SetXY(1,44.5);
    $tcpdf->Cell(30.5, 0, $nombreT, 0, 1, 'C', 0, '', 1);
    $tcpdf->SetXY(1,47.5);
    $tcpdf->Cell(30.5, 0, 'DNI '.$dni, 0, 1, 'C', 0, '', 1);
    $tcpdf->SetFont('arialn', 'B', 7);
    $tcpdf->SetXY(23,49);
    $tcpdf->Cell(30.5, 0, 'No '.$numero, 0, 1, 'C', 0, '', 1);
   
    // restore auto-page-break status
    $tcpdf->SetAutoPageBreak($auto_page_break, $bMargin);
    // set the starting point for the page content
    $tcpdf->setPageMark();
   
    //RETIRA DEL CARNET
   
    $tcpdf->AddPage();
    // get the current page break margin
    $bMargin = $tcpdf->getBreakMargin();
    // get current auto-page-break mode
    $auto_page_break = $tcpdf->getAutoPageBreak();
    // disable auto-page-break
    $tcpdf->SetAutoPageBreak(false, 0);
    $img_file = '../files/base/retira.jpg';
    $tcpdf->Image($img_file, 0, 0, 86, 54, '', '', '', false, 300, '', false, false, 0);
    //FIRMA
    $tcpdf->Image('../../Publicacion/Firmas/'.$dni.'.jpg', 25, 9, 38, 22, '', '', '', false, 72, '', false, false, 0);
    //CODIGO DE BARRAS
    $style = array(
        'position' => '',
        'align' => 'C',
        'stretch' => false,
        'fitwidth' => false,
        'cellfitalign' => '',
        'border' => false,
        'hpadding' => 'auto',
        'vpadding' => 'auto',
        'fgcolor' => array(0,0,0),
        'bgcolor' => false, //array(255,255,255),
        'text' => false,
        'font' => 'helvetica',
        'fontsize' => 12,
        'stretchtext' => 0
    );
    $tcpdf->SetXY(45,3);
    $tcpdf->write1DBarcode($dni, 'C128A', '', '', '39', 10, 0.9, $style, 'N');
    $tcpdf->SetFont('arialn', 'B', 9);
    $tcpdf->SetXY(26, 7.5);
    $tcpdf->Cell(84, 0, $fexp, 0, 1, 'L', 0, '', 0);
    //$tcpdf->Image('../../Publicacion/Firmas/'.$dni.'.jpg', 25, 9, 38, 22, '', '', '', false, 72, '', false, false, 0);
    $tcpdf->SetFont('arialn', 'B', 6);
    $tcpdf->SetXY(1,24);
    $tcpdf->Cell(84, 0, $nombre.' '.$apePat.' '.$apeMat, 0, 1, 'C', 0, '', 0);
    $tcpdf->SetFont('arialn', 'B', 5);
    $tcpdf->SetXY(1,26.5);
    $tcpdf->Cell(84, 0, $tipo.' '.$region.' - '.$provincia.' - '.$distrito, 0, 1, 'C', 0, '', 0);
    // ---------------------------------------------------------
   
    //Close and output PDF document
    $tcpdf->Output('carnet-'.$dni.'.pdf', 'I');


Pero tambien la uso para generar reportes y me soporta HTML con tablas, las tablas van de esta manera:

$pdf->writeHTML($tbl, true, false, false, false, '');

donde lo que va en $tbl, es todo mi codigo html incluido mi css:

por ejemplo mi cabecera:

        $pdf->SetFont('arialn', '', 8);
        $tbl = '
        <style>
        th {
        font-weight: bold;
        margin-left: 0.5cm;
        margin-right: 0.5cm;
        background-color:#D0D0D0;
        }
        </style>
        <table border="1">
        <tr>
        <th width="30" align="center"> Nro</th>
        <th width="80"> PROVINCIA</th>
        <th width="80"> DISTRITO</th>
        <th width="160"> GOBERNADOR</th>
        <th width="180"> DIRECCION ACTUAL</th>
        <th width="40" align="center"> DNI</th>
        <th width="60" align="center"> CELULAR</th>
        <th width="60" align="center"> RPM</th>
        <th width="60" align="center"> Telef. Fijo</th>
        <th width="130" align="center"> EMAIL</th>
        <th width="50" align="center"> Nro. Res.</th>
        <th width="60" align="center"> F. Nombr.</th>
        </tr>';

si tienes problemas usandolo como vendors, aqui hay un forma de usarlo creando un helper:

http://www.startutorial.com/articles/view/how-to-create-pdf-helper-with-tcpdf

en ese ejemplo las llamadas
$pdf->core->addPage('', 'USLETTER');

cambialas por:

$this->Pdf->core->
addPage('', 'USLETTER');

Saludos!

Aland Laines Calonge
Twitter: @lainessolutions



Aland Laines

unread,
Dec 4, 2012, 9:40:25 AM12/4/12
to cakep...@googlegroups.com
otra cosa alguien una ves paso esto en un post:

Venia con el mismo error al tratar de utilizar TCPDF y agregando 

ob_end_clean();

luego de 

App::import('Vendor','tcpdf');

se generó sin problemas....


Aland Laines Calonge
Twitter: @lainessolutions



2012/12/4 Aland Laines <aland....@gmail.com>
Reply all
Reply to author
Forward
0 new messages