tcpdf

PDF generation with TCPDF
28 followers

ETcPdf is a wrapper for the TCPDF class, which is not bundled, since it's huge (not so much the class itself, but the associated files, making a 9 Mb tarball or 13 Mb unpacked). You can download the class here. Notice that TCPDF is updated almost daily, so I recommend you to update the class file frequently, since new cool features are added on every release. I used TCPDF 4.2.007 while developing this wrapper.

Resources

Documentation

Requirements

  • Yii 1.0 or above
  • TCPDF 4.2.007 or above

Installation

  • Extract the release file under protected/extensions

TCPDF installation:

  • Download the tarball.
  • Unpack it on the extension directory.
  • If necessary, rename the resulting subdirectory to tcpdf
  • You just need to keep these subdirectories inside tcpdf: config, fonts and images, since the cache is stored on the runtime directory, and no docs are needed

Usage

See the following code example:

<?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");

Total 15 comments

#8044 report it
willowdan at 2012/05/05 05:52am
error %PDF-

The solution is to use blank layout, which only contains

<?php echo $content; ?>

This prevents any appending html tags to the generated pdf.

Cheers!

#6365 report it
Pablovp at 2012/01/03 11:20am
Solution for Constant K_PATH_CACHE already defined

Change line 85 from:

define ("K_PATH_CACHE", Yii::app()->getRuntimePath());

To:

if (!defined("K_PATH_CACHE")) 
{
    define ("K_PATH_CACHE", Yii::app()->getRuntimePath());
}
#6045 report it
MountainCastle at 2011/12/07 04:37pm
husnoo - tcpdf

@husnoo

Make sure you have a tcpdf subdirectory. Look in you folder structure you may have the files in extensions\tcpdf. If so move all the files in extensions\tcpdf to extensions\tcpdf\tcpdf.

#6033 report it
husnooo at 2011/12/07 02:48am
tcpdf

Hi,

i got the following error require_once(D:\Dev\Apache\htdocs\first\protected\extensions\tcpdf/tcpdf/tcpdf.php): failed to open stream: No such file or directory.

Please suggest the solution. thnks to all...

#5943 report it
ksorbo at 2011/11/27 07:32pm
How to use extend header / footer

I love the extension and am using it successfully.

One thing I haven't been able to figure out is how to replace the header footer functions of tcpdf. In order to be able to customize the footer, you must redefine the Footer function. Since this extension does not technically extend the tcpdf class, redefining the footer function does not work.

#5908 report it
MountainCastle at 2011/11/23 08:33pm
tcpdf

naga --

make sure you have a subdirectory called tcpdf with the tcpdf files(not the wrapper) in there. The wrapper files go in extensions\tcpdf in there you have a sub directory tcpdf that contains the tcpdf files

#4297 report it
naga at 2011/06/23 01:48am
tcpdf

Hi I got the following error require_once(D:\Dev\Apache\htdocs\first\protected\extensions\tcpdf/tcpdf/tcpdf.php): failed to open stream: No such file or director,

#4296 report it
naga at 2011/06/23 01:47am
tcpdf

i got the following error require_once(D:\Dev\Apache\htdocs\first\protected\extensions\tcpdf/tcpdf/tcpdf.php): failed to open stream: No such file or director

#3159 report it
trejder at 2011/03/22 06:45pm
Problems downloading main class

You can get source class of TCPDF from site mentioned by extension author (www.tecnick.com) or from www.tcpdf.org. But both sites gets often overloaded and results in timeouts instead of real content. In this situation, you may try to get the class from SourceForge, at: http://sourceforge.net/projects/tcpdf/.

#2634 report it
mpluss at 2011/01/24 07:57am
Table in the Header

Hi, I want to use a table in the Header. It dosen't work. Any Idea??

#2373 report it
doodleme at 2010/12/18 09:02am
K_PATH_CACHE

Saiful,

Try to comment off that line.

#2339 report it
saiful at 2010/12/14 10:29pm
I got error in the wrapper

I got the following error...

Constant K_PATH_CACHE already defined at line 85 of ETcPdf.php file

#391 report it
ertele at 2010/06/17 07:05am
error %PDF-

hi guys... I setting up this extension right now, but... i have one problem!! browser send me an alert.. it says:"file does not begin with '%PDF-'". I try the tcpdf library in a stand alone script (withous using YII) and it work fine!! i need help! thank you

PS i'm sorry for my bad english, i'm italian!! :D

#1455 report it
yingyang at 2009/07/30 08:41am
Not very high level (not at all) and so a questionable extension

An extension should actually give some functionality specific to the yii framework. This is actually just a "include tcpdf" done the yii way - there is NO functionalty like "print model data" or an auto-pdf-view generation or ANYTHING of interest. Thus it is nothing more than a fake addition to this extension collection and should be removed. A better place for this would be the tips and snippets wiki to show a way how to include libraries. But please rempove it from here to keep a clean extension collection.

#1630 report it
rickgrana at 2009/05/29 01:06pm
Array of configurations

I think you could add to the constructor an array parameter to put main information. Like this

$params = array("author" => "Nicola Asuni", "title" =>TCPDF Example 002", "subject" => "TCPDF Tutorial", "keywords"=>array("TCPDF, PDF, example, test, guide"), "header" => false, "footer" => false, "output" => "example_002.pdf");

$pdf = Yii::createComponent('application.extensions.tcpdf.ETcPdf', 'P', 'cm', 'A4', true, 'UTF-8', $params);

I think this should be more Yii-style.

Great Job!

Leave a comment

Please to leave your comment.

Create extension