PHP
  Home arrow PHP arrow Generate PDF Documents with PHP on the Windows Platform
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PHP

Generate PDF Documents with PHP on the Windows Platform
By: K.K.Sou
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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
     

       

    PHP ARTICLES

    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek