Home arrow PHP arrow Generate PDF Documents with PHP on the Windows Platform

Generate PDF Documents with PHP on the Windows Platform

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.

  1. Generate PDF Documents with PHP on the Windows Platform
  2. Hello world PDF
  3. Finding the filename of the truetype font
  4. Generating PDF documents for browsers
  5. Producing a simple bar graph in a PDF document
By: K.K.Sou
Rating: starstarstarstarstar / 9
September 16, 2008

print this article



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:


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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: