Part of the EllisLab Network
   
1 of 4
1
CodeIgniter Community Voice - Generating PDF files using CodeIgniter
Posted: 31 July 2008 01:33 PM   [ Ignore ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4777
Joined  03-23-2006

This week, our Community Voice author is Chris Monnat, known on the forums as mrtopher, who writes a helpful step by step guide to generating PDF files from CodeIgniter.  Chris is a full time web application developer and part time entrepreneur. In addition to building web sites for the medical industry during the day, at night Chris also runs his own development company Left of Center Communications. He recently started a personal blog at http://www.chrismonnat.com where he keeps a record of his exploits and discusses, among other things, CodeIgniter.

Read the full article

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

Profile
MSG
 
 
Posted: 31 July 2008 07:14 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
RankRank
Total Posts:  122
Joined  04-03-2007

Just curious if the author knew about www.tcpdf.org (TCPDF).  Seems like it does a lot more (an easier) than the cited library of choice.

Profile
 
 
Posted: 01 August 2008 03:40 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
RankRankRank
Total Posts:  340
Joined  10-02-2006

dompdf is reduced to “dom” in the article and thus generates a 404.

 Signature 

Dotted line.

Profile
 
 
Posted: 01 August 2008 06:26 AM   [ Ignore ]   [ # 3 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4777
Joined  03-23-2006
Crimp - 01 August 2008 07:40 AM

dompdf is reduced to “dom” in the article and thus generates a 404.

Got that fixed up now Crimp.  Thanks!

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

Profile
MSG
 
 
Posted: 01 August 2008 08:15 AM   [ Ignore ]   [ # 4 ]  
Grad Student
Rank
Total Posts:  61
Joined  06-03-2006
a&w; - 31 July 2008 11:14 PM

Just curious if the author knew about www.tcpdf.org (TCPDF).  Seems like it does a lot more (an easier) than the cited library of choice.

No, I wasn’t aware of this library but it looks interesting. I will have to check it out.

 Signature 

The blog: ChrisMonnat.com

Profile
 
 
Posted: 01 August 2008 08:42 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
RankRank
Total Posts:  122
Joined  04-03-2007

One more thought just FYI, the author and forum for TCPDF is very active still.  There are updates, enhancements, fixes on a frequent basis (sometimes a couple times a week).  Other libraries like FPDF and the one you cited haven’t had activity in years (as far as I could tell at a glance).

Profile
 
 
Posted: 01 August 2008 11:39 AM   [ Ignore ]   [ # 6 ]  
Grad Student
Rank
Total Posts:  61
Joined  06-03-2006

a&w;, your right. The development for the R&OS;library has stalled. As I said in the article, there are plenty of options out there for PDF libraries. I just chose to highlight the one that I use.

 Signature 

The blog: ChrisMonnat.com

Profile
 
 
Posted: 04 August 2008 07:50 AM   [ Ignore ]   [ # 7 ]  
Grad Student
Avatar
Rank
Total Posts:  34
Joined  12-10-2006

Hey guys !

Thanks for this very interesting article ! In fact, it came out just at the moment I needed it !

I’m experiencing some problems with this library with CI. Even with the most basic “Hello World!” code, the library returns an error (notice in fact) :

A PHP Error was encountered
Severity
Notice
Message
Undefined index
Filenamelibraries/class.pdf.php
Line Number
1934 

Then, with the same error on these lines

Line Number2421
Line Number
1631 

Then,

A PHP Error was encountere
Severity
Warning
Message
Cannot modify header information headers already sent by (output started at /opt/lampp/htdocs/acbulle/system/libraries/Exceptions.php:164)
Filenamelibraries/class.pdf.php
Line Number
1916 

And the same error on line 1917 and 1919

The PHP code is pretty basic :

$this->load->library('cezpdf');
$this->cezpdf->ezText('Hello World'12, array('justification' => 'center'));
$this->cezpdf->ezStream(); 

The files are in the correct directories, the font directory is readable and writable…

What’s wrong?
(I’m using CI 1.6.3)
Thanks !

PS: don’t know if it’s the right place to post, sorry if not.

 Signature 

: ) metalking

Profile
 
 
Posted: 04 August 2008 10:47 AM   [ Ignore ]   [ # 8 ]  
Lab Assistant
RankRank
Total Posts:  122
Joined  04-03-2007

metalking:

php is saying some variables haven’t been declared while the error_reporting is set to alert you of warnings.  You have two options: change the error_reporting in index.php to a lower level so it doesn’t display the warnings or go into the problem files and make sure the variables in question are declared properly.

The other errors will go away once you fix that, it’s just complaining that headers were already sent (ehco’ing the error message causes this error).

Profile
 
 
Posted: 05 August 2008 05:17 AM   [ Ignore ]   [ # 9 ]  
Grad Student
Avatar
Rank
Total Posts:  34
Joined  12-10-2006

Thanks a&w;!

In fact, I don’t know how to fix the missing variables because it is actually a library I downloaded. I doubt there is a problem with the library ‘cause many people use it without any problem.
I’ll try to lower the error_reporting level, but when another solution is possible, I’d prefer it, cause I need those reports for the development.

Thanks!

EDIT : Lol, the problem was this : I placed the “font” directory in a “static” subdirectory. I just moved it and now it works !
Thanks wink

 Signature 

: ) metalking

Profile
 
 
Posted: 18 August 2008 02:13 AM   [ Ignore ]   [ # 10 ]  
Grad Student
Avatar
Rank
Total Posts:  61
Joined  06-14-2008

Hi, I haven’t checked out the lib yet, but from the examples that you gave in the article, it looks like we have to insert every piece of text into the PDF by ourself, from headers, spacing, tables… which can be very tedious, especially for dynamic contents.

So, can I ask does this pdf lib give us the option to convert the whole page on the fly into a pdf file? I know a pdf lib for PHP that can do this, but cant remember the name right now. What it can do is: I include a button, say, ‘print’ on the page, and when user clicks it, it will automatically convert the whole page into PDF document and download it to the browser. It will use the normal css or print CSS if we have one. It works just as you have the adobe PDF print driver installed on your computer (well, not that good, but close). Can we do that with this library?

Thanks.
Khoa

Profile
 
 
Posted: 25 August 2008 09:36 AM   [ Ignore ]   [ # 11 ]  
Grad Student
Rank
Total Posts:  61
Joined  06-03-2006

Khoa, nope… this library can’t handle something like that. The R&OS;library is for those programmers who like to have access to ALL settings and such. I do know there are libraries that do what your referring to and I’ve even tried one or two. My issue with the ones I tries were they didn’t handle text formatting (bold, italics, etc.) very well. Plus, R&OS;handles tables very well where other libraries take more work.

It all boils down to personal preference.

 Signature 

The blog: ChrisMonnat.com

Profile
 
 
Posted: 01 September 2008 10:39 AM   [ Ignore ]   [ # 12 ]  
Summer Student
Avatar
Total Posts:  10
Joined  07-18-2007

Thanks for this intresting article, I’m nearly new to CI and before I used FPDF library who can use an existing PDF file to write on.
I have read (very fast) the R&OS;documentation and I haven’t found any function who can permit the same thing…

So (my english is poor) I don’t understand the doc or the feature is not prĂ©sent ?

Thank by advance.

Profile
 
 
Posted: 01 September 2008 05:55 PM   [ Ignore ]   [ # 13 ]  
Grad Student
Rank
Total Posts:  61
Joined  06-03-2006

If I understand you correctly, you are looking for a library that can use an existing PDF file to create a report. Is that correct?

If this is your question the answer is no. The R&OS;class does not provide this kind of functionality.

 Signature 

The blog: ChrisMonnat.com

Profile
 
 
Posted: 01 September 2008 07:07 PM   [ Ignore ]   [ # 14 ]  
Summer Student
Avatar
Total Posts:  10
Joined  07-18-2007

In fact I have a PDF document who have allready logo and text refinements and I put some informations on this document to generate a new document form DB and user input.
This is my syntax with FPDF :

$pdf = new fpdi();
$pagegab $pdf->setSourceFile("gabarit_per2.pdf");
$pagetpl $pdf->ImportPage(1);
$pdf->addPage();
$pdf->useTemplate($pagetpl,0,0,0);
// remplissage du pdf
$pdf->SetFont('Helvetica','',8);
$pdf->SetXY(85,51);
$pdf->Cell(80,8,utf8_decode("Saisie le ".date("d/m/Y")));
$pdf->SetFont('Helvetica','B',11);
$pdf->SetXY(120,47);
$pdf->Cell(50,8,$nabo);
$pdf->SetFillColor(0,0,0);
if (
$_POST['pervac']!=""){$pdf->Rect(26.5,71.5,3,3,'F');}
if ($_POST['perval']!=""){$pdf->Rect(77.5,71.5,3,3,'F');}
if ($_POST['peroedi']!=""){$pdf->Rect(129,71.5,3,3,'F');}
...
// generation du pdf
$fichier "bulletins/".$nabo.".pdf";
$pdf->Output($fichier,"F");
$pdf->closeParsers(); 

After reading carfully the doc of R&OS;he seems no capable to do that. :(

So, I continue to use FPDF, thanks anyway wink

Profile
 
 
Posted: 14 September 2008 08:07 PM   [ Ignore ]   [ # 15 ]  
Summer Student
Total Posts:  1
Joined  05-28-2008

Hi, thanx for this great article.

I’m just wondering if anyone knows if it is possible to have utf-8 support in R&OS;?

I tried to figure it out, but it still doesn’t work for me :(

Profile
 
 
   
1 of 4
1