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.
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).
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.
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: Filename: libraries/class.pdf.php Line Number: 1934
Then, with the same error on these lines
Line Number: 2421 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) Filename: libraries/class.pdf.php Line Number: 1916
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).
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
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?
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.
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…
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. :(