|
Creating PDF files on the fly using PHP PDF files can be generated using PHP. For creating PDF files using PHP or other languages you have to download and install PDFlib from PDFlib web-site. Installing PDFLib on Windows : 1) Unzip the zip file in any location , say, c:\pdflib
2)Now open the folder c:/pdflib/bind/php5/php503/
[if you are using PHP 5.3] ---------------OR---------------- open the folder c:/pdflib/bind/php4/php-430
[if you are using PHP 4.3] 3) copy the dll file "libpdf_php.dll"
4) Goto your your php insatallation folder and copy the dll file to C:\php\ext" folder,[assuming your php is in "c:\php" and "extension_dir" is "c:\php\ext".
5)Open your "php.ini" file and copy the line "extension=libpdf_php.dll" in your extension category Installing PDFLib on Unix : 1) Unzip the zip file in any location , say, ./pdflib
2)Now open the folder ./pdflib/bind/php5/php503/
[if you are using PHP 5.3] ---------------OR---------------- open the folder ./pdflib/bind/php4/php-430
[if you are using PHP 4.3] 3) copy the dll file "libpdf_php.so"
4) Goto your your php insatallation folder and copy the dll file to "./php/ext" folder,[assuming your php is in "./php" and "extension_dir" is "./php/ext"].
5)Open your "php.ini" file and copy the line "extension=libpdf_php.so" in your extension category Restart your web server. Now create a file named "fpdf.php" and paste the following code there <?php
$pdf = pdf_new();// create a new pdf file
$filename = "test1.pdf";// give the name of the file as test1.pdf
pdf_open_file($pdf, $filename);
pdf_set_info($pdf, "Author", "KoderGuru");// this is the header part and will not show on the
pdf_set_info($pdf, "Title", "Test for PHP wrapper of PDFlib 2.0");
pdf_set_info($pdf, "Creator", "See Author");
pdf_set_info($pdf, "Subject", "Testing");
pdf_begin_page($pdf, 595, 842); // this is the page size, 595*842 is the A$ page size
$font = pdf_findfont($pdf, "Times New Roman", "winansi", 1); // find "Times New Roman" font
pdf_setfont($pdf, $font, 20);
pdf_set_value($pdf, "textrendering", 1);
/* This is the type of Text Rendering
0 - Fill text
1 - Stroke text (outline)
2 - Fill and stroke test
3 - Invisible text
4 - Fill text and add to clipping path
5 - Stroke text and add to clipping path
6 - Fill and stroke text and add to clipping path
7 - Add text to the clipping path
*/
pdf_show_xy($pdf, "Hello World", 150, 750); // draw text "Hello World" at 150, 750 coordinate
pdf_moveto($pdf, 50, 740);
pdf_lineto($pdf, 330, 740); // draw a line strarting from current coordinate (50,740) upto (330,740)
pdf_stroke($pdf); //Stroke the path with the current color and line width
pdf_end_page($pdf);
pdf_close($pdf);
pdf_delete($pdf);
$len = filesize($filename);
// now show the pdf file using header function of php
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=$filename");
readfile($filename);
?> [You will see a stamp of PDFlib.com in the background if your PDFlib is a evaluation version] So that's the basic part. Hope you've enjoyed it . Thank You. Back to Tutorial Index page Your comments are most welcome admin@koderguru.com |