Creating PDF Files in php

by Rekha 2009-01-05 14:37:58

For creating PDF files in php you have to check whether the PDF library file in php is installed or not.You can use phpinfo() to check whether it is installed or not.If you don't find a PDF section in the phpinfo(), You have to install PDFLIB library using and download the latest version.

Uncomment the lines extension=libpdf_php.dll in php.ini file and restart your Web server so that the changes are recognized.

You will find PDFlib DSOs for various
versions of PHP on Windows in the following location of the uncompressed package:

Copy and paste the file in the PHP folder.Now PDF Library is installed.

Example for creating PDF file in php:

// create handle for new PDF document
$pdf = pdf_new();

// open a file
pdf_open_file($pdf, "philosophy.pdf");

// start a new page (A4)
pdf_begin_page($pdf, 595, 842);

// get and use a font object
$arial = pdf_findfont($pdf, "Arial", "host", 1); pdf_setfont($pdf, $arial, 10);

// print text
pdf_show_xy($pdf, "There are more things in heaven and earth, Horatio,", 50, 750); pdf_show_xy($pdf, "than are dreamt of in your philosophy", 50, 730);

// end page

// close and save file

This will create a new PDF file.

Tagged in:


You must LOGIN to add comments