Technology Blog

Widgets

Posts Tagged ‘pear’

PHP Pear File_PDF Install and Example

I personally like this package to create dynamic PDF files with PHP; however, the install instructions and documentation are horrible.

First of all, you need to have Pear installed
(open a cmd window on your server and run go-pear.bat from your PHP install directory)

Next to get File_PDF installed and working:
1. open a cmd window on your server
2. type: pear channel-update pear.php.net (hit enter)
3. type: pear upgrade-all (hit enter)
4. type: pear install HTTP_Download-1.1.3 (hit enter)
5. type: pear install File_PDF-0.3.2 File_PDF (hit enter)

That should get File_PDF installed along with all the upgraded dependencies

Now some code example:

  1.  
  2. <?php
  3. require (‘File/PDF.php’);
  4. $p = &File_PDF::factory(‘P’, ‘mm’, ‘A4′);
  5. $p->open();
  6. $p->setMargins(50, 50);
  7. $p->addPage(‘P’);
  8. $p->setFont(‘arial’, , 15);
  9. $p->write(10, ‘This is some text’);
  10. $p->text(10, 20, ‘Hello’);
  11. $p->close();
  12. $p->output(‘hello.pdf’);
  13. ?>
  14.  

Enjoy!

© ZADRO Solutions, Inc. All Rights Reserved. Disclaimer | Privacy Policy
RSS Facebook Digg Delicious Stumble Upon Twitter