Page 304 - Open Soource Technologies 304.indd
P. 304

Web Technologies-I



                   Notes
                                                You need to be careful of not violating any font license terms, because some
                                                fonts are not supposed to be embedded.

                                 12.3.5 Embedding Fonts

                                 To use nonstandard fonts, you must tell pdflib where they are with the FontAFM, FontPFM, or
                                 FontOutline parameters. For example, to use a TrueType font, you can do this:
                                 pdf_set_parameter($p,”FontOutline”,  “CANDY==/usr/fonts/candy.ttf”);  $font  =  pdf_
                                 findfont($p, “CANDY”, “host”, 1);
                                 The double equals sign in this code tells pdflib that you are specifying an absolute path. A single
                                 equals sign would indicate a path relative to the default font directory.
                                 Instead of using explicit pdf_set_parameter( ) calls each time you want to use a nonstandard font,
                                 you can tell your pdflib installation about these extra fonts by adding the FontAFM, FontPFM,
                                 and FontOutline settings to pdflib’s pdflib.upr file.

                                 Here’s a sample set of additions to the FontAFM and FontOutline sections of the pdflib.upr
                                 file. The line that starts with two slashes (//) indicates the default directory for font files. The
                                 format for the other lines is simply fontname=filename:
                                 //usr/share/fonts FontAFM LuciduxSans=lcdxsr.afm Georgia=georgia.afm FontOutline
                                 Arial=arial.ttf  Century Gothic=GOTHIC.TTF Century Gothic  Bold=GOTHICB.TTF  Century
                                 Gothic Bold Italic=GOTHICBI.TTF Century Gothic Italic=GOTHICI.TTF

                                 You can specify an absolute path to a font file if you wish.
                                 The following Example shows most of the built-in fonts along with the five extra AFM (Adobe
                                 Font Metric) and two extra TrueType fonts installed in the pdflib.upr file above. It displays new
                                 Euro currency symbol along with a collection of accented characters used in French.

                                               Font demonstration


                                 <?php
                                 $p = pdf_new( );

                                 pdf_open_file($p);
                                 pdf_set_info($p,”Creator”,”hello.php”);
                                 pdf_set_info;

                                 pdf_set_info($p,”Title”,”Hello world (PHP)”);
                                 pdf_set_parameter($p, “resourcefile”, ‘/usr/share/fonts/pdflib/pdflib.upr’);

                                 pdf_begin_page($p,612,792);
                                 pdf_set_text_pos($p,25,750);

                                 $fonts = array(‘Courier’=>0,’Courier-Bold’=>0,’Courier-BoldOblique’=>0, ‘Courier-Oblique’
                                 =>0,’Helvetica’=>0,’Helvetica-Bold’=>0, ‘Helvetica-BoldOblique’=>0,’Helvetica-Oblique’=>0,
                                 ‘Times-Bold’=>0,’Times-BoldItalic’=>0, ‘Times-Italic’=>0, ‘Times-Roman’=>0, ‘LuciduxSans’=>1,
                                 ‘Georgia’ => 1, ‘Arial’ => 1, ‘Century Gothic’ => 1, ‘Century Gothic Bold’ => 1, ‘Century Gothic
                                 Italic’ => 1, ‘Century Gothic Bold Italic’ => 1 );





        298                               LOVELY PROFESSIONAL UNIVERSITY
   299   300   301   302   303   304   305   306   307   308   309