Asher Sommer
Asher Sommer

Reputation: 53

Fpdf Chinese characters showing random character outputs

I have just converted my chinese fonts (simhei) via fpdf makefont to postscript so that I can use them in my fpdf output. So once I implement my Chinese text into my files, the characters showing are random characters other than the ones I typed.

Here is is the code:

$pdf2 = new PDF_Chinese('P', 'cm', 'Letter');
$pdf2->AliasNbPages();
$pdf2->AddGBFont('simhei','黑体');
$pdf2->AddGBFont('simkai','楷体_GB2312');

$pdf2->AddPage();

$pdf2->SetCompression(false);

$pdf2->SetAutoPageBreak(1,3);

$pdf2->SetDrawColor(200,200,200);

$pdf2->SetFont('simhei','',20.5);

$pdf2->Cell(0,1,'Black Bomb 目录批发价格 (批发)',0,0,'C');
$pdf2->SetFont('Arial','',7);`

This is the result

The characters are not the same as the ones in my code. Could it be that there went something wrong when I converted the font? Using fpdf makefont?

I tried to use different text to check if any characters are in the correct place. it seems like no characters would display as I put them in. Also Unicode characters, didn't fix the problem

Upvotes: 0

Views: 298

Answers (2)

SuperZoom Zoom
SuperZoom Zoom

Reputation: 1

The original Chinese text 'Black Bomb 目录批发价格 (批发)' is in "UTF-8". It is required to convert to "GB" format.

$in_str = 'Black Bomb 目录批发价格 (批发)';
$out_str = mb_convert_encoding($in_str, "gbk", "utf-8");
$pdf2->SetFont("simhei","", 20);
$pdf2->Cell(0,1,$out_str,0,0,'C');

The following line adds GB font, not UTF. Hence, UTF to GB conversion is required.

$pdf2->AddGBFont('simhei','黑体');

Upvotes: 0

Asher Sommer
Asher Sommer

Reputation: 53

Thanks @Olivier This did the job. After using tFPDF my problem is solved. Hereby I close this thread. Everybody who has problems adding Chinese characters to FPDF please use tFPDF instead. http://www.fpdf.org/en/script/script92.php

For simplified Chinese users. Please ignore all resources on the net, where people are explain how to convert Chinese fonts using TTFPT1.exe.

感谢 @Olivier.换到tFPDF解决的我的问题。 我现关闭这个讨论区。大家如果有问题加简体中文字使用FPDF请换成用tFPDF. 所有晚上的说明交给你们怎么换字母用TTFPT1.exe.可以忽视。

Upvotes: 1

Related Questions