|
Installation
Requirements
Installation
$ chgrp www-data lib/fonts If your user is not a member of the www-data group or you do not have root privileges, you can make the directory world writable and set the sticky bit: $ chmod 1777 lib/fonts Font InstallationNote for all platformsPDFs include support by default for Helvetica, Times-Roman, Courier and Zapf-Dingbats. You do not need to install any font files if you wish to use these fonts. This has the advantage of reducing the size of the resulting PDF, because additional fonts must be embedded in the PDF. Also, if you have problems installing the font files, you can try and use the distributed dompdf_font_family_cache.dist file in lib/fonts. Copy this file to lib/fonts/dompdf_font_family_cache and edit it directly to match the files present in your lib/fonts directory. Linux/UnixThe load_font.php utility installs and converts TrueType fonts for use with dompdf. Since CSS uses the concept of font families (i.e. the same face can be rendered in different styles & weights) dompdf needs to know which actual font files belong to which font family and which style. For example, the Microsoft core font pack includes the files !Verdana.ttf, Verdana_Italic.ttf, Verdana_Bold.ttf and Verdana_Bold_Italic.ttf. All four of these files need to be present in the dompdf font directory (DOMPDF_FONT_DIR), and entries need to be made in the dompdf_font_family_cache file. Given the font family name and the path to the 'normal' font face file (Verdana.ttf, in our example), load_font.php will search for the bold, italic and bold italic font face files in the same directory as the specified file. It searches for files with the same base name followed by 'Bold', 'B', or 'b' (similarly for italic and bold italic). If it can not find the correct files, you can specify them on the command line. In addition to copying the files to the dompdf font directory, it also generates .afm files. The R&OS CPDF class requires both the ttf file and an afm file, which describes glyph metrics. The afm file is generated using the ttf2pt1 utlity (available at http://ttf2pt1.sourceforge.net). If you are using the PDFLib backend, you will not need to create afm files for the fonts. load_font.php usage: $ ./load_font.php font-family n_file [b_file] [i_file] [bi_file] font_family - the name of the font, e.g. Verdana, 'Times New Roman', monospace, sans-serif.
Examples: $ ./load_font.php silkscreen /usr/share/fonts/truetype/slkscr.ttf
$ ./load_font.php 'Times New Roman' /mnt/c_drive/WINDOWS/Fonts/times.ttf
$ php -f load_font.php -- sans-serif /home/dude_mcbacon/myfonts/Verdana.ttf \
/home/dude_mcbacon/myfonts/V_Bold.ttfWindows(Note I don't have a windows test box at the moment, so these instructions may not work... If someone has tried this and has any suggestions for me, please send me an email!) Read the Linux/Unix section above first, as most of it applies. The main difference is the ttf2pt1 utility. Fortunately, there is a windows version, available at http://gnuwin32.sourceforge.net/packages/ttf2pt1.htm. You will have to edit your dompdf_config.inc.php file to point to the path where you installed ttf2pt1. You will also need the cli version of PHP in order to execute load_font.php, however it's usage is the same (see the last example above). |
Sign in to add a comment
I just installed this on a Windows server, and everything worked perfect, except the load_font.php. I hade GnuWin32? (ttf2pt1.exe) installed and it worked stand alone, but when I tried to run the PHP script, it acted like it was working, copied the TTF files correctly, but never generated the AFM files. Turns out, the problem lies in the path to the ttf2pt1.exe file in the config file for dompdf. The default install is here:
C:\Program Files\GnuWin32?\bin\ttf2pt1.exe
This is all good and well, but in the config file for dompdf, you have to specify the path to the executable as this:
C:\\Progra~1\\GnuWin32?\\bin\\ttf2pt1.exe
I know I had to do the double back slashes, but the Progra~1 is important, otherwise in essence the PHP exec command tries to run a program named "C:\Program" and fails due to the space.
The other issue involves line 231 in the load_font.php file:
exec( TTF2AFM . " " . escapeshellarg($font) . " " . $dest . " &> /dev/null", $output, $ret );
This is not compatible with Windows due to the &> /dev/null, since there is no such concept in Windows. To fix it, simply modify this line to be this:
exec( TTF2AFM . " " . escapeshellarg($font) . " " . $dest, $output, $ret );
There is no extra output from ttf2pt1 program, so it still looks the same, unless of course you have some strange error I'm sure.
I installed file-5.03-setup.exe downloaded from (http://sourceforge.net/projects/gnuwin32/files/file/file-5.03-setup.exe), then realised ttf2pt1.exe was not in the GnuWin32?/bin directory, I then downloaded the ttf2pt1.exe seperately and placed it in that directory.
I followed your instruction carefully,
1. Changed "C:\Program Files\GnuWin32??\bin\ttf2pt1.exe" to "C:\\Progra~1\\GnuWin32??\\bin\\ttf2pt1.exe" in dompdf_config.inc.php
2. deleted &> /dev/null" in "exec( TTF2AFM . " " . escapeshellarg($font) . " " . $dest . " &> /dev/null", $output, $ret );" in load_font.php
I then tried the code provided in usage examples from dompdf
<?php require_once("dompdf_config.inc.php"); //I made sure the path was correct $html =
$dompdf = new DOMPDF(); $dompdf->load_html($html);
$dompdf->render(); $dompdf->stream("hello_world.pdf");
?>
But it doesn't work................
Help please!
Carlos
I installed version 0.5.1 on Window Vista machine. I download and installed the ttf2pt1 utility from http://gnuwin32.sourceforge.net/packages/ttf2pt1.htm. I changed the path of TTF2AFM. I didn't make the other suggested change (#2) above. I ran a sample test and it works great. Thanks for providing this, Ryan.
Apache 2.2.11 PHP 5.2.9
Now, I'll see if I can get it working on a Linux environment.
Dear Vince Doherty,
Carlos
PHP 5.0.0+ with the DOM extension enabled. Note that the domxml PECL extenstion conflicts with the DOM extension and must be disabled.
And where in the world is this "PHP DOM extension"??? All I can see in my php.ini (I use XAMPP 1.7+Vista) is php_domxml.dll... which always shutdown my Apache..... I search in php.net and not a single guide on how to install.....
@blackjenova: I believe php_domxml.dll is the extension you should not enable. It is meant to be used with PHP 4. If you are using PHP 5+ you do not need to do anything as DOM support is baked in to PHP by default. See the following section of the PHP manual: http://www.php.net/manual/en/book.dom.php
The system requirements will be clarified/updated when we are closer to the release of the next version of DOMPDF.
If you have any additional questions, please post to the discussion group: http://groups.google.com/group/dompdf