Fpdf Chinese application Strategy

Source: Internet
Author: User
Tags vars

Reprinted from: http://www.cnblogs.com/zcy_soft/archive/2010/11/23/1885067.html

Once wrote about the use of FPDF articles, but because of quitting as you put blog server was attacked, the database out of the problem, now is not see, but the last blog was a lot of places reproduced, interested friends can go to search, Baidu with the keyword with "FPDF" and "Quit Like You", You will be able to see the content being reproduced.

Now to re-use the fpdf, so the use of the method again, you need to mention one point, At present, the official website of Fpdf (fpdf.org) is harmonious, login needs to use the agent, so the need to use the files to be organized here (the last 1.52 version of the Chinese manual is not provided this time, the English version is not difficult to understand).

Let's start by describing the packages that need to be used:
1, FPDF V 1.6 (Fpdf16.zip), which is currently seen in the latest version, August 3, 2008;
2, FPDF Chinese Bag (chinese.zip), seems to be TW's compatriots, can support for the simplified and complex;
3, TTF2TP1 (ttf2pt1.zip), font format conversion program, here is the win system with the executable file;
4, TTF2TP1 Chinese Pack (ttf2pt1-chinese-3.4.0.zip), it seems that the Code table.

First to make the Chinese font, the TTF2TP1 in the Ttf2tp1.exe extract to an easy to operate folder, because to use the command-line tool win, here is the "C:\ttf". Then the TTF2TP1 Chinese bag ugbk.map also extracted to this directory.

Find the font you want to handle from your win font folder, which is in bold (Simhei.ttf), and copy it to this folder.

Run C:\ttf\ttf2pt1.exe-a-l UGBK.MAP+A1 simhei.ttf Simhei in the command-line tool, especially: all the characters in the command are half-width, Online someone reprint quit smoking, such as your last article to turn two horizontal lines into full-width, some people run the prompt error, it is advisable not to copy, you use the keyboard input.

After a hard run, C:\ttf folder more out of the SIMHEI.AFM and simhei.t1a two files, the back of a useless, reserved Simhei.ttf and SIMHEI.AFM, for a while.

Unzip the Fpdf compressed package, using the fpdf.php files and/font/makefont folder, unzip or upload them to your server directory, if you use a Linux server, remember to change the/font folder properties to 777, The resulting font file to write to here.

The Fpdf Chinese bag chinese.php and ex.php two files extracted or uploaded to the root directory of fpdf.

Copy or upload the Simhei.ttf and simhei.afm just mentioned in the/font folder.

Create a file in the/font folder, such as:

PHP code
    1. <?php
    2. require ('./makefont/makefont.php ');
    3. MakeFont ('./simhei.ttf ', './simhei.afm ');
    4. ?>

Using a browser to browse the file, there are more than n things on the screen, regardless of it, as long as you see and generated two files simhei.php and simhei.z, the work of the production of fonts is completed, delete Simhei.ttf. Do multiple fonts to repeat the above work. After all the fonts are finished, you can delete the/font/makefont.php file and the/font/makefont folder. friends with Linux Server Remember to change the properties of the/font folder back.

Let's modify the/ex.php file, or simply rewrite the file:

PHP code
    1. <?php
    2. require  (
    3. &NBSP;
    4. $pdf  = new pdf_chinese ();
    5. $pdf  -> Addgbfont ( ' Simhei ', 
    6. $pdf  -> Open ();
    7. $pdf  -> AddPage ();
    8. $pdf  -> SetFont (
    9. $pdf  -> Write (10, 
    10. $pdf  -> Output ();
    11. ?>

Look in the browser, black out, right? But the effect seems to be not very satisfying, Chinese no problem, English spacing problems, is not it?

(Picture None)

The specific reason is that in the chinese.php file, quit smoking as you notice inside there is a variable called $gb_widths, it seems to define the width of English characters, quit smoking, such as you after a debugging, all English, character width all changed to 480, so there is the following test effect:

(Picture None)

This is quite satisfactory!

Reproduced from: http://www.cnblogs.com/zcy_soft/archive/2010/11/23/1885067.html

about resources: The resource connection in the above is not valid.

Fpdf can be found on the Fpdf website:

(1) http://www.fpdf.org

(2) Chinese suport:http://www.fpdf.org/phorum/read.php?f=1&i=5142&t=5142

Or, I will find the Fpdf package and Traditional Chinese manual, TTF2TP1, TTF2TP1 Chinese bag, etc. placed in the Baidu Cloud disk: Http://pan.baidu.com/s/1o6J1SGM

I practice the situation myself:

Requirements: Printed content is Chinese, digital, letter

Question 1: After quoting the chinese.php, it is still garbled in Chinese

Resolution 1: Use string iconv ( string $in_charset , string $out_charset , string $str )

Example 1 (without using the new font, directly using the chinese.php GB font):

1<?PHP2     require(' chinese.php ');3      4     $pdf=NewPdf_chinese ();5     $pdf-Addgbfont ();6     $pdf-AddPage ();7     $pdfSetFont (' GB ', ', 20);8     $pdfWrite (10, ' We are Chinese 1233 by Hubing.info ');9     $pdf-Output ();Ten?>
View Code

Question 2: The code for example 1 is normal, but I encountered a number in other places, the letter is always full-width form, the spacing is particularly large, modified $gb_widths in accordance with the original text.

Online looking for a long time to find the reason, and then a little bit to see, found to be due to chinese.php, using its own $GB _widths as a super-global variable processing.

In Example 1, $GB _widths is naturally a super global variable, but the place where I introduce chinese.php is a method in a class, $GB _widths is no longer hyper-global.

Resolution 2: Here, I stole a lazy, no deeper, in chinese.php the first definition $GB _widths = ... Change to $GLOBALS [' gb_widths '] = ....

In addition, the spacing of letters and numbers is not appropriate, you can modify the values in the $GB _widths according to the original text.

Fpdf Chinese application Strategy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.