PDF generation with PHP
yesterday marked the half way point in my self-imposed six month period of learning as much as necessary to consider myself a knowledgeable PHP programmer. another task i have wanted to figure out, and which only took an hour or so from idea to having a web page up, has been to create a PDF document dynamically with a PHP program (script).
PHP does not come with bundled with any module to create PDF's so it was necessary to download software that would. research showed that the "FPDF" library is one of the more commonly used libraries for this (fpdf.org). this is not a module but a class, so programming with it involves creating an object from this class.
i downloaded the .tgz file on my windows machine, used the SSH FTP client to drag it over to my linux server, and ran "tar -zxvf fpdf153.tgz" to unzip and extract everything.
then i created the php file which requires the "fpdf.php" file from the FPDF library, creates the FPDF object, fills it in, and outputs it- all in only 6 lines of code.
in the near future, i may use this class to create dynamic PDF letters of recommendation or other such web based forms that must be printed out in hard copy.
require('../../fpdf153/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Billy Bob');
$pdf->Output();
PHP does not come with bundled with any module to create PDF's so it was necessary to download software that would. research showed that the "FPDF" library is one of the more commonly used libraries for this (fpdf.org). this is not a module but a class, so programming with it involves creating an object from this class.
i downloaded the .tgz file on my windows machine, used the SSH FTP client to drag it over to my linux server, and ran "tar -zxvf fpdf153.tgz" to unzip and extract everything.
then i created the php file which requires the "fpdf.php" file from the FPDF library, creates the FPDF object, fills it in, and outputs it- all in only 6 lines of code.
in the near future, i may use this class to create dynamic PDF letters of recommendation or other such web based forms that must be printed out in hard copy.
require('../../fpdf153/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Billy Bob');
$pdf->Output();
1 Comments:
At 9:41 AM ,
Anonymous said...
how dynamically amazing!
Post a Comment
Subscribe to Post Comments [Atom]
<< Home