Part of the EllisLab Network
This thread is a discussion for the wiki article: TCPDF-CodeIgniter Integration
   
 
TCPDF-CodeIgniter Integration
Posted: 23 June 2009 04:42 AM   [ Ignore ]  
Summer Student
Total Posts:  16
Joined  03-09-2009

hi friends, Could any one post a working example for tcpdf integrated with codeigniter.I want a view file (which contains html tables, images).converted to pdf

Profile
 
 
Posted: 24 August 2009 12:49 AM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  286
Joined  02-12-2009

Jonathon Hill!

Thanks for the quick and dirty addition of TCPDF!

Got it working inside 15 minutes (SVN, file and class naming, etc)

Thanks again!

 Signature 

.htaccess mod_rewrite no longer working when moving from the development server to production server?

Check that you have AllowOverride All in your host config file for the public web directory of your website.

AND USE THE FRACKING SEARCH!!!  it works, it really does!

Profile
 
 
Posted: 26 October 2009 12:24 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  36
Joined  03-07-2009

Anyone have any idea what version of tcpdf the integration library was designed to work with?

Profile
 
 
Posted: 12 January 2010 08:02 AM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  4
Joined  09-08-2008

This comment refers to tcpdf_4_8_021, the latest version as of this posting.
Upon setting this up as instructed and running the pdf_test controller (pdf_test/tdpdf), I got an error re: K_CELL_HEIGHT_RATIO as undefined. I determined this was on the first run through of application/3rdparty/tcpdf/tcpdf.php and changed line 950
from: protected $cell_height_ratio = K_CELL_HEIGHT_RATIO;
to: protected $cell_height_ratio;

Now the example runs without error.

You can also comment out line 137 in the same file:
require_once(dirname(__FILE__).’/config/tcpdf_config.php’);

as this is nullified as line 32 of application/3rdparty/tcpdf/config/tcpdf_config.php states:
// If you define the constant K_TCPDF_EXTERNAL_CONFIG, the following settings will be ignored.

K_TCPDF_EXTERNAL_CONFIG is set as TRUE in the first lines of the pdf.php library file.

I think it helps to understand that all of the original config file is ignored. Use the original config file as a reference for items in later versions that may need to be replicated in the custom config.

I also renamed the custom config file to tcpdf_ci and made the necessary path and url corrections, because I don’t like having two files with the same name, but this is not necessary.
I hope this helps someone.

Profile
 
 
Posted: 14 January 2010 04:23 AM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  18
Joined  01-14-2010

Thanks, got the TCPDF library working, but i cant seem to send it as an email attachment, how do I save the file to a temporary directory and then delete it after sending it? (please forgive my sloppy code) smile

controller example:

function email_pdf()
    
{
            $this
->load->library('pdf');

            
// set document information
            
$this->pdf->SetSubject('TCPDF Tutorial');
            
$this->pdf->SetKeywords('TCPDF, PDF, example, test, guide');

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

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

            
// print a line using Cell()
            
$this->pdf->Cell(0, 12, 'Example 001 - €à èéìòù', 1, 1, 'C');

            
//$this->pdf->AddPage();
            // PRINT VARIOUS 1D BARCODES

            
$testbarcode = '127236487236487';

            
// CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
            
$this->pdf->Cell(0, 0, 'CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9', 0, 1);
            
$this->pdf->write1DBarcode($testbarcode, 'C39', '', '', 80, 30, 0.4);

            
//$this->$pdf->Ln();

            //Close and output PDF document
        
$filename = "pdt_example_001.pdf";
        
$this->pdf->Output($filename, 'I');
    
        
$this->load->library('email', $config);
        
$this->email->set_newline("\r\n");
        
        
$this->email->from('email@email.com', 'your name');
        
$this->email->to('email@email.com');
        
$this->email->subject('subject');
        
$this->email->message('It is working. Great! Wooohooo!');
        
        
         
//Close and output PDF document
        
$this->email->attach($filename);
          
        
        if(
$this->email->send()) {
            
echo 'your email has been sent, fooool!';
        
}
        
else {
            show_error
($this->email->print_debugger());
        
}
        
echo $this->email->print_debugger();
    
}
}

this results in a pdf displaying in the window, and an empty email being sent. please help!

Profile
 
 
Posted: 18 January 2010 03:30 AM   [ Ignore ]   [ # 5 ]  
Summer Student
Total Posts:  18
Joined  01-14-2010

I solved it myself smile

$filename = "pdt_example_001.pdf";
$path = $this->config->item('server_root');
$file = $path . '/folder/attachments/test.pdf';
// F to save as file
attachmentPdf = $this->pdf->Output($file, 'F');

// and then delete file when sent
unlink($file);
Profile
 
 
Posted: 13 February 2010 06:51 PM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  189
Joined  09-12-2007

I am getting a “Maximum function nesting level of ‘100’ reached” error. The current version of tcpdf is 4.8.033. Anyone else getting this error?

 Signature 

Voltamp Media
Web: PHP, MySQL, PERL, HTML, CSS, Python, Javascript
Linux: FreeBSD, OpenVPN, SMB, SVN, C, Shell

Profile
 
 
Posted: 19 February 2010 08:35 PM   [ Ignore ]   [ # 7 ]  
Summer Student
Total Posts:  1
Joined  02-19-2010

bsauls: I got the same error and resolved it with your instructions, so yes, your post did help smile

Profile
 
 
Posted: 08 March 2010 06:36 PM   [ Ignore ]   [ # 8 ]  
Summer Student
Total Posts:  3
Joined  03-08-2010
Eric Cope - 13 February 2010 06:51 PM

I am getting a “Maximum function nesting level of ‘100’ reached” error. The current version of tcpdf is 4.8.033. Anyone else getting this error?


I’m getting the same error with 4.8.036

I seem to be stuck in this loop:
[08-Mar-2010 18:29:20] PHP   4. TCPDF->AddPage() modules/analysis/interpretation_wizard/printable_report.class.php:87
[08-Mar-2010 18:29:20] PHP   5. TCPDF->startPage() includes/tcpdf/tcpdf.php:2399
[08-Mar-2010 18:29:20] PHP   6. TCPDF->setHeader() includes/tcpdf/tcpdf.php:2456
[08-Mar-2010 18:29:20] PHP   7. TCPDF->Header() includes/tcpdf/tcpdf.php:2698
[08-Mar-2010 18:29:20] PHP   8. TCPDF->Cell() includes/tcpdf/tcpdf.php:2626
[08-Mar-2010 18:29:20] PHP   9. TCPDF->checkPageBreak() includes/tcpdf/tcpdf.php:3711
[08-Mar-2010 18:29:20] PHP 10. TCPDF->AddPage() includes/tcpdf/tcpdf.php:3665
[08-Mar-2010 18:29:20] PHP 11. TCPDF->startPage() includes/tcpdf/tcpdf.php:2399
[08-Mar-2010 18:29:20] PHP 12. TCPDF->setHeader() includes/tcpdf/tcpdf.php:2456
[08-Mar-2010 18:29:20] PHP 13. TCPDF->Header() includes/tcpdf/tcpdf.php:2698
[08-Mar-2010 18:29:20] PHP 14. TCPDF->Cell() includes/tcpdf/tcpdf.php:2626
[08-Mar-2010 18:29:20] PHP 15. TCPDF->checkPageBreak() includes/tcpdf/tcpdf.php:3711

Oddly it ends with:
[08-Mar-2010 18:29:20] PHP 95. TCPDF->endPage() includes/tcpdf/tcpdf.php:2397
[08-Mar-2010 18:29:20] PHP 96. TCPDF->setFooter() includes/tcpdf/tcpdf.php:2415
[08-Mar-2010 18:29:20] PHP 97. TCPDF->SetFont() includes/tcpdf/tcpdf.php:2739
[08-Mar-2010 18:29:20] PHP 98. TCPDF->AddFont() includes/tcpdf/tcpdf.php:3387
[08-Mar-2010 18:29:20] PHP 99. TCPDF->empty_string() includes/tcpdf/tcpdf.php:3195
[08-Mar-2010 18:29:20] PHP 101. TCPDF->__destruct() includes/tcpdf/tcpdf.php:0
[08-Mar-2010 18:29:20] PHP 102. TCPDF->_destroy() includes/tcpdf/tcpdf.php:1638

Please let me know if you’ve figured out the cause.

Profile
 
 
Posted: 08 March 2010 07:12 PM   [ Ignore ]   [ # 9 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  189
Joined  09-12-2007

I never found the problem. I finally switched to domPDF and am able to process the same html without issues.

 Signature 

Voltamp Media
Web: PHP, MySQL, PERL, HTML, CSS, Python, Javascript
Linux: FreeBSD, OpenVPN, SMB, SVN, C, Shell

Profile
 
 
Posted: 08 March 2010 07:13 PM   [ Ignore ]   [ # 10 ]  
Summer Student
Total Posts:  3
Joined  03-08-2010

Thanks for the reply. Unfortunately, I’m migrating from FPDF to TCPDF for utf8 support so I think it might be more difficult for me to switch to domPDF.

Profile
 
 
Posted: 19 March 2010 02:31 PM   [ Ignore ]   [ # 11 ]  
Summer Student
Total Posts:  2
Joined  03-19-2010

Followed instructions.

$this->load->library('pdf');

throws error:

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 1572864 bytes) in [...]\app\3rdparty\tcpdf\unicode_data.php on line 4197

Has anyone else seen this? Using latest, current version of tcpdf (tcpdf_4_8_038).

It’s my Windows dev machine (will end up being on Linux)... Gonna try it on the production server right now…

Update: Got the same error on the server. At least after I sorted out the permissions problems. Guess I’ll start sifting through the code myself on Monday. hmmm

Profile
 
 
Posted: 19 March 2010 02:34 PM   [ Ignore ]   [ # 12 ]  
Summer Student
Total Posts:  3
Joined  03-08-2010

You need to bump up your memory limit in php.ini

For what it’s worth I got TCPDF to work for my problem. I had some classes that extended class TCPDF and the biggest change I had to make was correctly calling the parent constructor.

Profile
 
 
Posted: 19 March 2010 03:15 PM   [ Ignore ]   [ # 13 ]  
Summer Student
Total Posts:  2
Joined  03-19-2010

Yeah, I was just looking for another solution. Throwing resources at a problem can end bad (I’ve seen poorly coded scripts that error out one day (up the memory limit) and then again a couple weeks later (up it again? no, you fix it)) so I try to avoid it if I can. In this particular instance I had to up it locally to 16MB, and then even higher to 24MB on the server. =(

Thanks!

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120568 Total Logged-in Users: 36
Total Topics: 126614 Total Anonymous Users: 2
Total Replies: 665605 Total Guests: 354
Total Posts: 792219    
Members ( View Memberlist )