Exploring the Future Potential of AI-Enabled Smartphone Processors
PHP and PDFLib
1. PHP and PDFlib
South Florida PHP Users Group
Adam Culp
http://www.Geekyboy.com
In 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.
3. Installation
Installation 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. Free VS Commercial
PDFlib 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. Capabilities
Too 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. Basics
To 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. Structure
Necessary 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);