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");
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
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.
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!
Table in the Header
Hi,
I want to use a table in the Header. It dosen't work.
Any Idea??
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/.
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,
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
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.
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...
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.
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()); }
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!
TCPDF ERROR: Some data has already been output, can't send PDF file
i have a view and want its pdf format. how can i get ?
i have this code
$this->renderPartial('application.views.reportcard.report',array(
'student_info'=>$student_info, ));
$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");
how to load view
how i tell tcpdf to generate pdf of particular view ?
Answer to @ranairfan
Unfortunately this extension is not a converter from HTLM to PDF. It 'just' give you access to the tcpdf function you must draw your report by yourself...
tcpdf version 6
just installed the extension and
solved the "K_PATH_CACHE already defined" error thanks to @Pablovp
but, now i get the following error:
call_user_func_array() expects parameter 1 to be a valid callback, class 'TCPDF' does not have a method 'AliasNbPages'
any cues?
AliasNbPages error
I confirm same error report for me.
I delete the line
and then it works again .I do not know precisely the consequences...
but seems this methods no more exist in tcpdf.
line at top of page
I have started using tcpdf and have it working, but for a mysterious line that appears at the top of the page. I have just the following as code, yet the line keeps appearing:
$pdf = Yii::createComponent('application.extensions.tcpdf.ETcPdf', 'P', 'cm', 'A4', true, 'UTF-8'); $pdf->SetFont('dejavusans', 'B', 16, '', true); $pdf->AddPage(); $pdf->Cell(0, 0, $pdf->header_title, 0, 1, 'L', 0, '', 0); $pdf->Output('invoice.pdf', 'I');
Anyone else have this issue?
issue with header and footer
I have issue with header and footer.. how to set header and footer and how to erase the line at top and bottom of the pages...? can anyone help with this issue?
header and footer
The answer lies in this link:
Your text to link here...
Custom Header / Footer
To create custom header / footer you have to extend the basic class TCPDF and define methods Footer() / Header(). It is more complicated if you are using ETCPDF because you have to edit constructor in ETcPdf.php. I created one more parameter and based on it's value constructor desides which object will be used to fill variable myTCPDF.
// etcpdf.php require_once(dirname(__FILE__).'/myTCPDF.php'); public function __construct($orientation, $unit, $format, $unicode, $encoding, $docType = null) { switch ($docType) { case null: $this->myTCPDF = new TCPDF($orientation, $unit, $format, $unicode, $encoding); return; break; case 'myPdf': $this->myTCPDF = new myTCPDF($orientation, $unit, $format, $unicode, $encoding); return; break; } } // myTCPDF.php require_once(dirname(__FILE__).'/tcpdf/tcpdf.php'); class myTCPDF extends TCPDF { public function Header() { // ... } public function Footer() { // .. } }
You also have to change methods in etcpdf.php:
public function __call($method, $params) { return call_user_func_array(array($this->myTCPDF, $method), $params); } public function __set($name, $value) { $this->myTCPDF->$name = $value; } public function __get($name) { return $this->myTCPDF->$name; }
Or should I do it in another way? What If I want to generate 10 different PDFs with different headers and footers? Do I really have to extend TCPDF 10x? Or can ETCPDF solve this situation?
PDF should be as my Page...
I have already implemented this extension.. How can I get exported file as my page look like.. what can I do??
Thank in advance..
error call_user_func_array() expects parameter 1 to be a valid callback, class 'TCPDF' does not have a method 'AliasNbPages'
just change
to
Loading file.
I recieved this Error: "Failed to load PDF document"
someone know how solve this.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.