Free cms blog design page
Home Joomla Hacking creating pdf whmcs
creating pdf whmcs  E-mail
User Rating: / 0
PoorBest 

TCPDF Installation

TCPDF can be downloaded from SourceForge.net.

 

 $pdf->Image(ROOTDIR.'/images/logo.png',20,25,75);

75 is with next is hight

/**
        * Sets the font used to print character strings.
        * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).
        * The method can be called before the first page is created and the font is retained from page to page.
        * If you just wish to change the current font size, it is simpler to call SetFontSize().
        * Note: for the standard fonts, the font metric files must be accessible. There are three possibilities for this:<ul><li>They are in the current directory (the one where the running script lies)</li><li>They are in one of the directories defined by the include_path parameter</li><li>They are in the directory defined by the K_PATH_FONTS constant</li></ul><br />
        * @param string $family Family font. It can be either a name defined by AddFont() or one of the standard Type1 families (case insensitive):<ul><li>times (Times-Roman)</li><li>timesb (Times-Bold)</li><li>timesi (Times-Italic)</li><li>timesbi (Times-BoldItalic)</li><li>helvetica (Helvetica)</li><li>helveticab (Helvetica-Bold)</li><li>helveticai (Helvetica-Oblique)</li><li>helveticabi (Helvetica-BoldOblique)</li><li>courier (Courier)</li><li>courierb (Courier-Bold)</li><li>courieri (Courier-Oblique)</li><li>courierbi (Courier-BoldOblique)</li><li>symbol (Symbol)</li><li>zapfdingbats (ZapfDingbats)</li></ul> It is also possible to pass an empty string. In that case, the current family is retained.
        * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li><li>D: line trough</li></ul> or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats basic fonts or other fonts when not defined.
        * @param float $size Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12
        * @since 1.0
        * @see AddFont(), SetFontSize()
        */

 

 

TCPDF Fonts

TCPDF supports TrueTypeUnicode (UTF-8 Unicode), OpenTypeUnicode, TrueType, OpenType, Type1, CID-0 and Core (standard) fonts.
All TCPDF fonts must be embedded on the PDF document, unless you are using standard fonts whith Unicode mode disabled.

The PDF Core (standard) fonts are:

  • courier : Courier
  • courierb : Courier Bold
  • courierbi : Courier Bold Italic
  • courieri : Courier Italic
  • helvetica : Helvetica
  • helveticab : Helvetica Bold
  • helveticabi : Helvetica Bold Italic
  • helveticai : Helvetica Italic
  • symbol : Symbol
  • times : Times New Roman
  • timesb : Times New Roman Bold
  • timesbi : Times New Roman Bold Italic
  • timesi : Times New Roman Italic
  • zapfdingbats : Zapf Dingbats

Setting up a font for usage with TCPDF requires the following steps:

  1. Convert all font filenames to lowercase.
     
  2. Generate the font's metrics file.
    • 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.exe) 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.
    • For TrueTypeUnicode or TrueType font files, use the the provided ttf2ufm utility (fonts/utils/ttf2ufm.exe):
      $ ttf2ufm -a -F myfont.ttf
    • For OpenTypeUnicode or OpenType font files, use the the provided ttf2ufm utility (fonts/utils/ttf2ufm.exe):
      $ ttf2ufm -a -F myfont.otf
  3. Run makefont.php script.
    • For TrueTypeUnicode:
      $ php -q makefont.php myfont.ttf myfont.ufm
    • For OpenTypeUnicode:
      $ php -q makefont.php myfont.otf myfont.ufm
    • For TrueType:
      $ php -q makefont.php myfont.ttf myfont.afm
    • For OpenType:
      $ php -q makefont.php myfont.otf myfont.afm
    • For Type1:
      $ php -q makefont.php myfont.pfb myfont.afm
    You may also specify additional parameters:
    MakeFont(string $fontfile, string $fmfile [, boolean $embedded [, $enc="cp1252" [, $patch=array()]]])
    • $fontfile : Path to the .ttf or .pfb file.
    • $fmfile : Path to the .afm file for Type1 and TrueType or .ufm for TrueTypeUnicode.
    • $embedded : Set to false to not embed the font, true otherwise (default).
    • $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:
      • cp1250 (Central Europe)
      • cp1251 (Cyrillic)
      • cp1252 (Western Europe)
      • cp1253 (Greek)
      • cp1254 (Turkish)
      • cp1255 (Hebrew)
      • cp1257 (Baltic)
      • cp1258 (Vietnamese)
      • cp874 (Thai)
      • iso-8859-1 (Western Europe)
      • iso-8859-2 (Central Europe)
      • iso-8859-4 (Baltic)
      • iso-8859-5 (Cyrillic)
      • iso-8859-7 (Greek)
      • iso-8859-9 (Turkish)
      • iso-8859-11 (Thai)
      • iso-8859-15 (Western Europe)
      • iso-8859-16 (Central Europe)
      • koi8-r (Russian)
      • koi8-u (Ukrainian)
      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.
    • $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').
  4. Copy the resulting .php, .z and .ctg.z (if available) files to the TCPDF fonts directory.
     
  5. Rename php font files variations using the following schema:
    • [basic-font-name-in-lowercase].php for regular font
    • [basic-font-name-in-lowercase]b.php for bold variation
    • [basic-font-name-in-lowercase]i.php for oblique variation
    • [basic-font-name-in-lowercase]bi.php for bold oblique variation

Set the Font

On the configuration file (config/tcpdf_config.php) set the K_PATH_FONTS constant to the TCPDF fonts path.
On the fourth parameter of the TCPDF class constructor you have to specify if you are using Unicode fonts (true) or old fonts (false).

To set the font in your script you just need to call the SetFont() method. It is mandatory to call this method at least once before printing text or the resulting document would not be valid. The method can be called before the first page is created and the font is retained from page to page:

SetFont(string family[,string style[,string size]])
  • family Family font. It can be either a font name or one of the standard families (case insensitive):
    • Courier (fixed-width)
    • Helvetica or Arial (synonymous; sans serif)
    • Times (serif)
    • Symbol (symbolic)
    • ZapfDingbats (symbolic)
    It is also possible to pass an empty string. In that case, the current family is retained.
  • style Font style. Possible values are (case insensitive):
    • empty string: regular
    • B: bold
    • I: italic
    • U: underline
    or any combination. The default value is regular.
  • size Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12.

Example:

$pdf->SetFont("vera", "BI", 20);

Reducing the Size of TrueType Fonts

Font files are often quite voluminous; this is due to the fact that they contain the characters corresponding to many encodings. zlib compression reduces them but they remain fairly big. A technique exists to reduce them further. It consists in converting the font to the Type1 format with ttf2ufm by specifying the encoding you are interested in; all other characters will be discarded. For instance, the arial.ttf font shipped with Windows 98 is 267KB (it contains 1296 characters). After compression it gives 147. Let's convert it to Type1 by keeping only cp1250 characters:

ttf2ufm -b -L cp1250.map c:/windows/fonts/arial.ttf arial

The .map files are located in the makefont directory. The command produces arial.pfb and arial.afm. The arial.pfb file is only 35KB, and 30KB after compression.

It is possible to go even further. If you are interested only in a subset of the encoding (you probably don't need all 217 characters), you can open the .map file and remove the lines you are not interested in. This will reduce the file size accordingly.

 arial.ttf

ariali.ttf 

arialbi.ttf 

arialbd.ttf 

 

D:\temp\tcpdf\cache>ttf2ufm -a -F ariali.ttf

 D:\temp\tcpdf\cache>ttf2ufm -a -F ariali.ttf

 

 

srv2# php -q makefont.php arial.ttf arial.ufm iso-8859-2

srv2# php -q makefont.php ariali.ttf ariali.ufm iso-8859-2
Font file compressed (ariali.z)
CIDToGIDMap created and compressed (ariali.ctg.z)
Font definition file generated (ariali.php)

Set the Font

On the configuration file (config/tcpdf_config.php) set the K_PATH_FONTS


 

 

 


 

 

 

 

BlinkList     Del.icio.us     Digg This!     Diigo Diigo    Facebook     Furl     Google     Ma.gnolia     Mr. Wong     Seed Newsvine     Reddit     Slashdot     Stumble It!     Technorati     Yahoo MyWeb
 

Add your comment

Your name:
Your website:
Subject:
Comment:
  The word for verification. Lowercase letters only with no spaces.
Word verification:
The $5 Script Archive
The best of PHP, MySQL, Flash and XML technologies, brought together at one low price.

 

 

Group 2 Tab

Group 4 Tab

Yesterday all servers in the U.S. went out on strike in a bid to get more RAM and better CPUs. A spokes person said that the need for better RAM was due to some fool increasing the front-side bus speed. In future, buses will be told to slow down in residential motherboards.