Subversion Repositories Applications.annuaire

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
296 aurelien 1
TCPDF Fonts
2
 
3
TCPDF supports TrueTypeUnicode (UTF-8 Unicode), OpenTypeUnicode, TrueType, OpenType, Type1, CID-0 and Core (standard) fonts.
4
 
5
There are two ways to use a new font: embedding it in the PDF (with or without subsetting) or not. When a font is not embedded, it is searched in the system. The advantage is that the PDF file is lighter; on the other hand, if it is not available, a substitution font is used. So it is preferable to ensure that the needed font is installed on the client systems. If the file is to be viewed by a large audience, it is recommended to embed.
6
 
7
TCPDF support font subsetting to reduce the size of documents using large unicode font files.
8
If you embed the whole font in the PDF, the person on the other end can make changes to it even if he didn't have your font.
9
If you subset the font, file size of the PDF will be smaller but the person who receives your PDF would need to have your same font in order to make changes to your PDF.
10
The option for enabling/disabling the font subsetting are explained on the source code documentation for methods SetFont() and AddFont().
11
 
12
The fonts that could be not embedded are only the standard core fonts and CID-0 fonts.
13
 
14
The PDF Core (standard) fonts are:
15
 
16
    * courier : Courier
17
    * courierb : Courier Bold
18
    * courierbi : Courier Bold Italic
19
    * courieri : Courier Italic
20
    * helvetica : Helvetica
21
    * helveticab : Helvetica Bold
22
    * helveticabi : Helvetica Bold Italic
23
    * helveticai : Helvetica Italic
24
    * symbol : Symbol
25
    * times : Times New Roman
26
    * timesb : Times New Roman Bold
27
    * timesbi : Times New Roman Bold Italic
28
    * timesi : Times New Roman Italic
29
    * zapfdingbats : Zapf Dingbats
30
 
31
Setting up a font for usage with TCPDF requires the following steps:
32
 
33
   1. Convert all font filenames to lowercase and rename using the following schema:
34
          * [basic-font-name-in-lowercase].ttf for regular font
35
          * [basic-font-name-in-lowercase]b.ttf for bold variation
36
          * [basic-font-name-in-lowercase]i.ttf for oblique variation
37
          * [basic-font-name-in-lowercase]bi.ttf for bold oblique variation
38
 
39
   2. Generate the font's metrics file.
40
          * For Type1 font files this first step is not necessary because the AFM file is usually shipped with the font. In case you have only a metric file in PFM format, use the pfm2afm utility (fonts/utils/pfm2afm) to get the AFM file. If you own a Type1 font in ASCII format (.pfa), you can convert it to binary format with Type 1 utilities.
41
          * For TrueTypeUnicode or TrueType font files, use the the provided ttf2ufm utility (fonts/utils/ttf2ufm):
42
 
43
            $ ttf2ufm -a -F myfont.ttf
44
 
45
          * For OpenTypeUnicode or OpenType font files, use the the provided ttf2ufm utility (fonts/utils/ttf2ufm):
46
 
47
            $ ttf2ufm -a -F myfont.otf
48
 
49
   3. Run makefont.php script.
50
          * For TrueTypeUnicode:
51
 
52
            $ php -q makefont.php myfont.ttf myfont.ufm
53
 
54
          * For OpenTypeUnicode:
55
 
56
            $ php -q makefont.php myfont.otf myfont.ufm
57
 
58
          * For TrueType:
59
 
60
            $ php -q makefont.php myfont.ttf myfont.afm
61
 
62
          * For OpenType:
63
 
64
            $ php -q makefont.php myfont.otf myfont.afm
65
 
66
          * For Type1:
67
 
68
            $ php -q makefont.php myfont.pfb myfont.afm
69
 
70
      You may also specify additional parameters:
71
 
72
      MakeFont(string $fontfile, string $fmfile [, boolean $embedded [, $enc="cp1252" [, $patch=array()]]])
73
 
74
          * $fontfile : Path to the .ttf or .pfb file.
75
          * $fmfile : Path to the .afm file for Type1 and TrueType or .ufm for TrueTypeUnicode.
76
          * $embedded : Set to false to not embed the font, true otherwise (default).
77
          * $enc : Name of the encoding table to use. Default value: cp1252. Omit this parameter for TrueType Unicode, OpenType Unicode and symbolic fonts like Symbol or ZapfDingBats. The encoding defines the association between a code (from 0 to 255) and a character. The first 128 are fixed and correspond to ASCII. The encodings are stored in .map files. Those available are:
78
                o cp1250 (Central Europe)
79
                o cp1251 (Cyrillic)
80
                o cp1252 (Western Europe)
81
                o cp1253 (Greek)
82
                o cp1254 (Turkish)
83
                o cp1255 (Hebrew)
84
                o cp1257 (Baltic)
85
                o cp1258 (Vietnamese)
86
                o cp874 (Thai)
87
                o iso-8859-1 (Western Europe)
88
                o iso-8859-2 (Central Europe)
89
                o iso-8859-4 (Baltic)
90
                o iso-8859-5 (Cyrillic)
91
                o iso-8859-7 (Greek)
92
                o iso-8859-9 (Turkish)
93
                o iso-8859-11 (Thai)
94
                o iso-8859-15 (Western Europe)
95
                o iso-8859-16 (Central Europe)
96
                o koi8-r (Russian)
97
                o koi8-u (Ukrainian)
98
            Of course, the font must contain the characters corresponding to the chosen encoding. The encodings which begin with cp are those used by Windows; Linux systems usually use ISO.
99
          * $patch : Optional modification of the encoding. Empty by default. This parameter gives the possibility to alter the encoding. Sometimes you may want to add some characters. For instance, ISO-8859-1 does not contain the euro symbol. To add it at position 164, pass array(164=>'Euro').
100
 
101
   4. Edit and copy resulting files by case:
102
          * For embedded fonts: copy the resulting .php, .z and .ctg.z (if available) files to the TCPDF fonts directory.
103
          * For not-embedding the font, edit the .php file and comment the $file entry.
104
          * For CID-0 fonts (not embeddeed) you have to edit the .php file:
105
                o change the font type to: $type='cidfont0';
106
                o set the default font width by adding the line: $dw=1000;
107
                o remove the $enc, $file and $ctg variables definitions
108
                o add one of the following blocks of text at the end of the file (depends by the language you are using - see the arialunicid0.php file for a working example):
109
                      + // Chinese Simplified
110
                        $enc='UniCNS-UTF16-H';
111
                        $cidinfo=array('Registry'=>'Adobe', 'Ordering'=>'CNS1','Supplement'=>0);
112
                        include(dirname(__FILE__).'/uni2cid_ac15.php');
113
 
114
                      + // Chinese Traditional
115
                        $enc='UniGB-UTF16-H';
116
                        $cidinfo=array('Registry'=>'Adobe', 'Ordering'=>'GB1','Supplement'=>2);
117
                        include(dirname(__FILE__).'/uni2cid_ag15.php');
118
 
119
                      + // Korean
120
                        $enc='UniKS-UTF16-H';
121
                        $cidinfo=array('Registry'=>'Adobe', 'Ordering'=>'Korea1','Supplement'=>0);
122
                        include(dirname(__FILE__).'/uni2cid_ak12.php');
123
 
124
                      + // Japanese
125
                        $enc='UniJIS-UTF16-H';
126
                        $cidinfo=array('Registry'=>'Adobe', 'Ordering'=>'Japan1','Supplement'=>5);
127
                        include(dirname(__FILE__).'/uni2cid_aj16.php');
128
 
129
                o copy the .php file to the TCPDF fonts directory.
130
   5. Rename php font files variations using the following schema:
131
          * [basic-font-name-in-lowercase].php for regular font
132
          * [basic-font-name-in-lowercase]b.php for bold variation
133
          * [basic-font-name-in-lowercase]i.php for oblique variation
134
          * [basic-font-name-in-lowercase]bi.php for bold oblique variation
135