Yii Framework Forum: [EXTENSION] PDF generation with TCPDF - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[EXTENSION] PDF generation with TCPDF Rate Topic: -----

#1 User is offline   MetaYii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 393
  • Joined: 07-October 08
  • Location:The Matrix

Posted 13 November 2008 - 04:58 PM

Feel free to discuss this extension here.

http://www.yiiframew...extension/tcpdf
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,906
  • Joined: 04-October 08
  • Location:DC, USA

Posted 13 November 2008 - 05:03 PM

Very nice work indeed! Are you converting your prado components into Yii's?
0

#3 User is offline   MetaYii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 393
  • Joined: 07-October 08
  • Location:The Matrix

Posted 13 November 2008 - 05:11 PM

Quote

Are you converting your prado components into Yii's?


Yes, I'm trying to (and I learn Yii and more PHP OOP in the process :-) ). I'm not able to release everything, since several are commercial closed source work (and most of those not generic nor useful outside my projects), but the ones I can, I will, to give back to the project and the FLOSS community.
0

#4 User is offline   bitmatix 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 162
  • Joined: 23-March 09

Posted 24 March 2009 - 07:55 AM

I'm trying to do add some html to a pdf by doing the following in my controller class:

$html = $this->renderPartial('_details', array('model' => $model), true);
$pdf->writeHTML($html, true, false, false, false, '');

but I get the following error:

array_push() [<a href='function.array-push'>function.array-push</a>]: First argument should be an array

it seems like the writeHTML doesn't accept the html code, which is returned by the renderPartial function.

could anyone help me?
0

#5 User is offline   CoLT 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 246
  • Joined: 22-November 09

Posted 15 January 2010 - 07:28 AM

View Postbitmatix, on 24 March 2009 - 07:55 AM, said:

I'm trying to do add some html to a pdf by doing the following in my controller class:

$html = $this->renderPartial('_details', array('model' => $model), true);
$pdf->writeHTML($html, true, false, false, false, '');

but I get the following error:

array_push() [<a href='function.array-push'>function.array-push</a>]: First argument should be an array

it seems like the writeHTML doesn't accept the html code, which is returned by the renderPartial function.

could anyone help me?


More working examples would be useful as its not working now.
0

#6 User is offline   gallego123 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 535
  • Joined: 11-August 09
  • Location:Argentina

Posted 05 February 2010 - 10:17 AM

i get error with same images

$pdf->Image($imagen, 1, 1.5, 3, 3, '', '', '', true, 600, '',false,false,1);


this not work http://i50.tinypic.com/2cc1lt.gif
but this work fine http://i48.tinypic.com/2qi2ooo.jpg

the extension is not a problem, the reverse also happens

help

[edit]

the problem is the size of image
i resize to 95x95 and work
but 100x100 not work
help me!!!

This post has been edited by Horacio Segura: 08 February 2010 - 08:56 AM

KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
0

#7 User is offline   gallego123 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 535
  • Joined: 11-August 09
  • Location:Argentina

Posted 08 February 2010 - 04:53 PM

i do a test

download source from http://sourceforge.n...ts/tcpdf/files/

put tcpdf in host an run example 9

http://localhost/tcp...example_009.php
work fine

after this

1) create a new webapp with yicc webapp (test)
2) install extension tcpdf
3) modify site/index.php putting code of example 9
change
  require_once('../config/lang/eng.php');
  require_once('../tcpdf.php');


for

  Yii::import('application.extensions.*');
  require_once('tcpdf/config/lang/eng.php');
  require_once('tcpdf/tcpdf.php');


put image "image_demo.jpg" in /images
change
$pdf->Image('../images/image_demo.jpg', 50, 50, 100, 150, '', 'http://www.tcpdf.org', '', true, 150);

for
$pdf->Image('images/image_demo.jpg', 50, 50, 100, 150, '', 'http://www.tcpdf.org', '', true, 150);true, 150);

and... error


now pleads

anyone can tell me if I do something wrong, or is a bug in the framework?

someone with time can do the same test that I do

thanks
KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
0

#8 User is offline   gallego123 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 535
  • Joined: 11-August 09
  • Location:Argentina

Posted 09 February 2010 - 06:48 AM

hi

me again

i probe http://www.fpdf.org/ tutorial 2

and get same error with large images

how debug this? is a bug?


[edit]

the error is "an eror has ocurred while trying to use this document"
only happend with large image
try with browsers :mozilla and chrome
OS:ubuntu and winXP

This post has been edited by Horacio Segura: 09 February 2010 - 11:14 AM

KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
0

#9 User is offline   gallego123 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 535
  • Joined: 11-August 09
  • Location:Argentina

Posted 11 February 2010 - 05:21 AM

the problem is solved
i get this error because i use this classes in views
but the correct use is in controller <_<

sorry

i newbie
KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
0

#10 User is offline   dfortun 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 01-June 11

Posted 07 June 2011 - 08:54 AM

View PostHoracio Segura, on 11 February 2010 - 05:21 AM, said:

the problem is solved
i get this error because i use this classes in views
but the correct use is in controller <_<

sorry

i newbie



Do you have some example for the newbies like me???
0

#11 User is offline   gallego123 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 535
  • Joined: 11-August 09
  • Location:Argentina

Posted 07 June 2011 - 10:15 AM

View Postdfortun, on 07 June 2011 - 08:54 AM, said:

Do you have some example for the newbies like me???


mmmmm, yes


	public function actionImprime($idEgreso)
	{


                       $egreso=Egreso::model()->with('dom_estado')->findByPk($idEgreso);

                       $criteria= new CDbCriteria();
                       $criteria->condition='idEgreso='.$idEgreso;
                       $criteria->order='idEgresoDetalle';
                       $detalles=EgresoDetalles::model()->findAll($criteria);
                

                $ancho=21;
                $alto=29.7;
                $format=array($ancho,$alto);


                $pdf = Yii::createComponent('application.extensions.tcpdf.tcpdf.MyTcPDF');
                $pdf->SetCreator(PDF_CREATOR);
                $pdf->SetAuthor(Yii::app()->name);
                $pdf->SetTitle("Remito Egreso");


$programa=$egreso->programa->nombre;
$efector=$egreso->efector->nombre;

$medico=($egreso->medico)?$egreso->medico->profesional->persona->nombre.', '.$egreso->medico->profesional->persona->apellido:'';
$paciente=($egreso->padron)?$egreso->padron->persona->nombre.' '.$egreso->padron->persona->apellido:'';

$estado=Varios::descripcionDominio('DR_ESTADO_EGRESO',$egreso->estado);

$anio=substr($egreso->fecha,6,4);
$titulo='REMITO DE '.strtoupper($programa).' ('.$egreso->nroRemito.'/'.$anio.')';




$cabecera = <<<EOD

<br />
<br />
<b>Efector:</b> <font size="18">$efector </font>
<br />
<b>Programa:</b> $programa 
<br />

<b>Remito:</b> $egreso->nroRemito/$anio
<br />
<b>Estado:</b>$estado
<br />

<b>Fecha:</b>$egreso->fecha
<br />
<b>Médico Solicitante:</b>$medico
<br />
<b>Paciente:</b>$paciente
<br />

EOD;


                $pdf->SetHeaderData('logocpsp.jpg', 0,$titulo,$cabecera);


                // set header and footer fonts
                $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
                $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

                // set default monospaced font
                $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

                //set margins
                $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
                $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
                $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
                $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
                $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);


                /*Primer página*/
                $pdf->AddPage();

                

$tbl = <<<EOD
    <font size="8">
    <table border="1" >
    <thead>
     <tr style="background-color:#666666;">
      <td width="35" align="center"><b>Reng</b></td>
      <td width="45" align="center"><b>Cant</b></td>
      <td width="280" align="center"><b>Medicamento</b></td>
      <!--<td width="100" align="center"> <b>Presentación</b></td>-->
      <td width="70" align="center"><b>Vto.</b></td>
      <td width="70" align="center"><b>Lote</b></td>
     </tr>
    </thead>
EOD;

foreach ($detalles as $i => $renglon) {
                $medicamento=$renglon->producto->nombre;
                $presentacion=$renglon->producto->presentacion;
                $fechaVto=$renglon->lote->fecha_vto;
                $lote=$renglon->lote->lote;
                $nroRenglon=$i+1;
                $tbl .= <<<EOD
                 <tr>
                  <td width="35" align="center">$nroRenglon</td>
                  <td width="45" align="center">$renglon->cantidad</td>
                  <td width="280">$medicamento</td>
                  <!--<td width="100"> $presentacion</td>-->
                  <td width="70" align="center">$fechaVto</td>
                  <td width="70" align="center">$lote</td>
                 </tr>
EOD;

}

$tbl .= <<<EOD
</table>
</font>
EOD;

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



$tbl = <<<EOD

<font size="8">
<table border="1">
<thead>
 <tr style="background-color:#666666;">
  <td width="125" align="center"><b>Autoriza</b></td>
  <td width="125" align="center"><b>Prepara</b></td>
  <td width="125" align="center"><b>Resp Téc.</b></td>
  <td width="125" align="center"> <b>Recibe</b></td>
 </tr>
</thead>
<tr>
  <td  width="125" align="center" height="50" > &nbsp;</td>
  <td  width="125" align="center" height="50" > &nbsp;</td>
  <td  width="125" align="center" height="50" > &nbsp;</td>
  <td  width="125" align="center" height="50" > &nbsp;</td>
 </tr>
 <tr align="center">
  <td width="125"  > Firma</td>
  <td width="125"  > Firma</td>
  <td width="125"  > Firma</td>
  <td width="125"  > Firma</td>
 </tr>
<tr>
  <td  width="125" height="50" > &nbsp;</td>
  <td  width="125" height="50" > &nbsp;</td>
  <td  width="125" height="50" > &nbsp;</td>
  <td  width="125" height="50" > &nbsp;</td>
 </tr>

<tr align="center">
  <td width="125">Aclaración</td>
  <td width="125">Aclaración</td>
  <td width="125">Aclaración</td>
  <td width="125">Aclaración</td>
 </tr>
 <tr>
  <td width="125" >Fecha:   </td>
  <td width="125" >Fecha:   </td>
  <td width="125" >Fecha:   </td>
  <td width="125" >Fecha:   </td>
 </tr>
</table>
</font>

EOD;

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

if (!empty($paciente)) {
        $tbl = <<<EOD
                <font size="8">
                <table border="1">
                <thead>
                 <tr style="background-color:#666666;">
                  <td  width="500" align="center"><b>Paciente</b></td>
                 </tr>
                </thead>
                <tr>
                  <td  width="500"  height="40">&nbsp;</td>
                </tr>

                <tr>
                  <td width="500" align="center">(Firma, Aclaración y Fecha)</td>
                </tr>
                </table>
                </font>

                

EOD;

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

} 




if (!empty($egreso->obs)) {
        $tbl = <<<EOD
                <font size="8">
                <table border="1">
                <thead>
                 <tr style="background-color:#666666;">
                  <td  width="500" align="center"><b>Observaciones</b></td>
                 </tr>
                </thead>

                <tr>
                  <td  width="500" >$egreso->obs</td>
                </tr>
                </table>
                </font>
                
EOD;

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

}

if (!empty ($egreso->fechaLimiteEnvio))
        $pdf->writeHTML('<b> Fecha limite de envío:'.$egreso->fechaLimiteEnvio.'</b>', true, false, false, false, '');

$pdf->writeHTML('<b> Fecha Salida Droguería: <br> Transporte:</b>', true, false, false, false, '');



//pongo una linea y leyenda
$tbl='<hr> <div align="center"><b>DEVOLVER CONFORMADO A ORGANISMO CENTRAL </b> <br> <b>DENTRO DE LOS 10 (DIEZ) DÍAS CORRIDOS</b> </div>';
$pdf->writeHTML($tbl, true, false, false, false, '');

                // reset pointer to the last page
                $pdf->lastPage();
                $pdf->Output($egreso->programa->nombre.'    '.$egreso->nroRemito.'\/'.substr($egreso->fecha,6,4). '.pdf', "D");
                

	}


Attached File(s)


KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
0

#12 User is offline   dfortun 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 01-June 11

Posted 07 June 2011 - 12:27 PM

View PostHoracio Segura, on 07 June 2011 - 10:15 AM, said:

mmmmm, yes



What is MyTcPDF?
How/Where do you call your action 'actionImprime'?

I have a 'Preview' button, and my idea is to generate the PDF when I click it. I am really lost with this stuff
0

#13 User is offline   gallego123 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 535
  • Joined: 11-August 09
  • Location:Argentina

Posted 07 June 2011 - 02:10 PM

View Postdfortun, on 07 June 2011 - 12:27 PM, said:

What is MyTcPDF?

my custom TcPdf

Quote

How/Where do you call your action 'actionImprime'?

from the view ....

Quote

I have a 'Preview' button, and my idea is to generate the PDF when I click it. I am really lost with this stuff

try with something like this

CHtml::button('preview', array('submit' => array('imprime','id'=>$data->id)));

KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
0

#14 User is offline   dfortun 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 01-June 11

Posted 07 June 2011 - 02:15 PM

View PostHoracio Segura, on 07 June 2011 - 02:10 PM, said:

my custom TcPdf


from the view ....


try with something like this

CHtml::button('preview', array('submit' => array('imprime','id'=>$data->id)));



One last question, How I create a custon TcPdf??? copy/paste and change the name of the file?
0

#15 User is offline   John_453P 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 24-March 11

Posted 21 September 2011 - 05:41 PM

I use this code
protected/view/site/index
<?php

Yii::import('application.extensions.tcpdf.*');
require_once('config/lang/eng.php');
require_once('tcpdf.php');;

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 002');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// set font
$pdf->SetFont('times', 'BI', 20);

// add a page
$pdf->AddPage();

// set some text to print
$txt = <<<EOD
TCPDF Example 002

Default page header and footer are disabled using setPrintHeader() and setPrintFooter() methods.
EOD;

// print a block of text using Write()
$pdf->Write($h=0, $txt, $link='', $fill=0, $align='C', $ln=true, $stretch=0, $firstline=false, $firstblock=false, $maxh=0);

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('example_002.pdf', 'I');

?>

and result : Failed To Load PDF Document, how to resolve..?? Please help me.. :-[
0

#16 User is offline   arip 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 99
  • Joined: 25-September 11

Posted 08 November 2011 - 12:29 PM

I have code this
<?php
$pdf = Yii::createComponent('application.extensions.tcpdf.ETcPdf', 'P', 'cm', 'A4', true, 'UTF-8');
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor("Nicola Asuni");
$pdf->SetTitle("TCPDF Example 002");
$pdf->SetSubject("TCPDF Tutorial");
$pdf->SetKeywords("TCPDF, PDF, example, test, guide");
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont("times", "BI", 20);
$pdf->Cell(0,10,"Example 002",1,1,'C');
$pdf->Output("example_002.pdf", "I");
?>


but when I open file PDF canot, I get error message 'not PDF file or corrupted'.

sorry I am newbie.

please help me
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users