Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

PHP and PDFLib

1,993 views

Published on

Using PDFLib with PHP 101

Published in: Technology
  • Be the first to comment

  • Be the first to like this

PHP and PDFLib

  1. 1. PHP and PDFlibSouth Florida PHP Users Group Adam Culp http://www.Geekyboy.comIn this session we will cover some basics of using PDFlib with PHP. We will install the application, cover where to find more info and resources, and basic usage.
  2. 2. PHP and PDFlibThe Source Http://www.pdflib.com/
  3. 3. InstallationInstallation is as easy as 1-2-3 Copy the application to modules directory /usr/lib/php5/20090626+lfs Add module to php.ini (extension=libpdf_php.so) Restart Apache Use PDFLib
  4. 4. Free VS CommercialPDFlib has a lite version as well as Commercial Lite is free, but limited functionally Lite is not pre-compiled Commercial is fully functional (for $1.1K, or $2.2K) Commercial can be used fully, but has watermark until licensed.
  5. 5. CapabilitiesToo many capabilities to cover here... Merge multiple PDF files Fill in form on PDF and save Create complex document layout Populate pre-built blocks in PDF
  6. 6. BasicsTo use PDFlib in PHP you simply: Instantiate PDFlib Customize your object Output two ways Dump to screen from buffer as download header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=businesscard.pdf"); Save to hard drive with file_put_contents
  7. 7. StructureNecessary code elements: $p = new PDFlib(); $p->begin_document($outfilename, "openmode=none"); $p->begin_page_ext(10, 10, ""); // add stuff here using methods $p->end_page_ext(""); $p->end_document(""); $buf = $p->get_buffer(); $len = strlen($buf); // output to browser as download header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=hello.pdf"); print $buf; // or save to disk file_put_contents($searchpath . / . $filename, $buf);

×