PHP
  Home arrow PHP arrow Generate PDF Documents with PHP on the...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Generate PDF Documents with PHP on the Windows Platform
By: K.K.Sou
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-09-16

    Table of Contents:
  • Generate PDF Documents with PHP on the Windows Platform
  • Hello world PDF
  • Finding the filename of the truetype font
  • Generating PDF documents for browsers
  • Producing a simple bar graph in a PDF document

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Generate PDF Documents with PHP on the Windows Platform


    (Page 1 of 5 )

    If you're a PHP programmer who has tried to generate PDF documents on the Windows platform, you may have run into some very irritating issues. This article will discuss those issues, show you how to generate PDF documents that can be viewed on a desktop and through a browser, and help you troubleshoot if you run into problems.

    Try Googling for "generate pdf with php." You can probably find hundreds of articles with many sample codes here and there.

    However, if you try these sample codes on a Windows platform, you will most likely get the following error:


    "PHP Fatal error: Uncaught exception 'PDFlibException' with message 'Metrics data for font 'Arial' not found'. "

    So where and how do you specify this "Metrics data for font" that is required to generate the PDF documents with PHP on Windows?

    Setting up the PDF library

    Before you can generate PDF documents, first you need to make sure the php_pdf.dll containing the PDFLib library is properly set up.

    You can find a copy of php_pdf.dll in the download area of the official PHP web site.

    If you are running a thread-safe version of PHP, download the “PECL 5.2.5 Win32 binaries” file. If you are running a non thread-safe version of PHP, download the “PECL 5.2.5 Non-thread-safe Win32 binaries” file. If you do not know whether your PHP is thread-safe or non thread-safe, just try one of these first. If it doesn't work, try the other.

    Unzip the file to a folder. You will find a lot of dlls in there. You only need one of these -- the php_pdf.dll. Copy just that file to the “ext” folder where you have installed your PHP.

    Next open up php.ini in your favorite editor and add the following line:


    extension=php_pdf.dll


    Now we are ready to generate pdf documents using PHP on Windows.

    Notes on the different versions of php_pdf.dll

    One of the major problems people face is that there are so many different versions of php_pdf.dll floating around on the Internet. Also, different people are running different versions of PHP on their servers. On top of this, there are the thread-safe and non thread-safe compilations of PHP and the dll. The two need to match.

    This is complicated by the fact that the PDFLib library is now maintained by PDFlib GmbH. While the library is free for testing and developing purposes, you need to purchase a license for commercial use. If you go to PDFlib GmbH, you can see that the latest version of PDFLib is now version 7. However, the php_pdf.dll available from the official PHP site is still version 5.

    This partly explains why many of the sample codes you found on the Internet and the official PHP site do not work. Those examples might work on Linux, as it is easy for Linux users to recompile PHP with the latest pdf library. But they might not work on Windows, as most of the available php_pdf.dll is relatively outdated.

    More PHP Articles
    More By K.K.Sou


       · I have few questions about this content. when I download both "PECL 5.2.5 Win32...
       · It's pecl-5.2.6-Win32.zip. 1.unzip it.2.you can find php_pdflib.dll.3.copy it...
       · the version of pecl is the same as your version of php.
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT