



$arial = pdf_findfont($pdf, "Arial", "host", 1) pdf_setfont($pdf, $arial, 10) The pdf_findfont() function prepares a font for use within the document, and requires the name of the font, the encoding to be used, and a Boolean value indicating whether or not the font should be embedded in the PDF file it returns a font object, which may be used via a call to pdf_setfont(). Selecting and registering a font is accomplished via the pdf_findfont() and pdf_setfont() functions. In this case, all I’m doing is writing a line of text to the document – so all I need to do is pick a font, and then use that font to write the text string I need to the document.
#Php pdf images code#
In between the calls to pdf_begin_page() and pdf_end_page() comes the code that actually writes something to the PDF document, be it text, images or geometric shapes.
#Php pdf images manual#
In case math isn’t your strong suit, the PHP manual provides width and height measurements for most standard page sizes, including A4, the one used in the example above. Note that the pdf_begin_page() function requires two additional parameters, which represent the width and height of the page to be created in points (a point is 1/72 of an inch). Pdf_begin_page() function, start a new page (A4) pdf_begin_page($pdf, 595, 842) Īnd end pages with the – you guessed it! – pdf_end_page() function. Once a document has been created, you can insert new pages in it with the open a file pdf_open_file($pdf, "philosophy.pdf") Next up, you need to give the PDF file a name – this is accomplished via the pdf_open_file() function, which requires the handle returned in the previous operation, together with a user-defined file name. This handle is then used in all subsequent operations involving the PDF document. This is accomplished via the pdf_new() function, which returns a handle to the document. create handle for new PDF document $pdf = pdf_new() Let’s take the first step - creating a handle for the PDF document. Let’s take a closer look at the code used in the example above.Ĭreating a PDF file in PHP involves four basic steps: creating a handle for the document registering fonts and colours for the document writing or drawing to the handle with various pre-defined functions and saving the final document. Here’s what you’ll see when you open the file: PHP will execute the script, and a new PDF file will be created and stored in the location specified at the top of the script. Save this file, and then browse to it through your Web browser. Once you’ve got everything in place, it’s time to create a simple PDF file.
#Php pdf images download#
You can download a copy of this reader from If you’re running Windows, your job is even simpler – a pre-built PDF library is bundled with your distribution, and all you need to do is activate it by uncommenting the appropriate lines in your PHP configuration file.Īdditionally, you’ll need a copy of the (free!) Adobe Acrobat PDF reader, so that you can view the documents created via the PDFLib library.

If you’re working on Linux, you can download a copy from and compile it for your box. In order to use PHP’s PDF manipulation capabilities, you need to have the PDFLib library installed on your system. Over the next few pages, I’m going to take a quick look at this module, providing you with a brief overview of its functions and demonstrating how you can use it in your PHP development.
#Php pdf images portable#
One of the more interesting items currently being bundled with PHP is the PDFLib extension, which allows developers to dynamically generate documents in Adobe Portable Document Format (PDF). Extensions available today allow developers to use PHP to perform IMAP and POP3 operations dynamically construct images and Shockwave Flash movies perform credit card validation encrypt sensitive data and parse XML-encoded data. The language invites extensibility, making it easy for developers to add new modules to the core engine, and widespread community support has made PHP one of the most full-featured Web programming languages around, with support for a wide variety of modular extensions. One of the reasons I like PHP so much is its consistent support for new technologies.
