Home arrow PHP arrow Page 3 - Generate PDF Documents with PHP on the Windows Platform

Finding the filename of the truetype font - PHP

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.

TABLE OF CONTENTS:
  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
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

In case you do not know the filename of the respective truetype fonts, just open up your fonts folder in the explorer (usually itís c:windowsfonts) and choose View - Details. You will see something similar to the following:



The first column shows the descriptive font name, and the second column gives you the filename of the true type font.

Specifying two or more fonts

You can set up two or more fonts with multiple statements of pdf_set_parameter():


pdf_set_parameter($pdf, 'FontOutline', 'Arial=c:windowsfontsarial.ttf');

pdf_set_parameter($pdf, 'FontOutline', 'Times New Roman=c:windowsfontstimes.ttf');

pdf_set_parameter($pdf, 'FontOutline', 'Verdana=c:windowsfontsverdana.ttf');


followed by:


$font1 = pdf_findfont($pdf, "Arial", "host", 1);

$font2 = pdf_findfont($pdf, "Times New Roman", "host", 1);

$font3 = pdf_findfont($pdf, "Verdana", "host", 1);


Below is a complete sample code that will produce the following PDF document:




<?php

# pdf_example2.php


// create a new pdf document

$pdf = pdf_new();

pdf_open_file($pdf, 'pdf_example2.pdf');


// start a new page (Letter size)

pdf_begin_page($pdf, 612, 792);


// setup font

pdf_set_parameter($pdf, 'FontOutline',

'Arial=c:windowsfontsarial.ttf');

pdf_set_parameter($pdf, 'FontOutline', 'Times New Roman=c:windowsfontstimes.ttf');

pdf_set_parameter($pdf, 'FontOutline',

'Verdana=c:windowsfontsverdana.ttf');


$font1 = pdf_findfont($pdf, "Arial", "host", 1);

$font2 = pdf_findfont($pdf, "Times New Roman", "host", 1);

$font3 = pdf_findfont($pdf, "Verdana", "host", 1);


pdf_setfont($pdf, $font1, 20);

pdf_show_xy($pdf, "This is Arial at 20 pt.", 50, 680);


pdf_setfont($pdf, $font2, 24);

PDF_continue_text($pdf, "This is Times New Roman at 24 pt.");


pdf_setfont($pdf, $font3, 36);

PDF_continue_text($pdf, "This is Verdana at 36 pt.");


// done

pdf_end_page($pdf);

pdf_close($pdf);

pdf_delete($pdf);

echo "pdf_example2.pdf has been generatedn";


?>




 
 
>>> More PHP Articles          >>> More By K.K.Sou
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- 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: