3

I am using FPDF to create a PDF and tFPDF to allow for unicode characters, such as Chinese, Japanese, or Korean.

I am using the ex.php that was in the tFPDF example files.

I added some Japanese and Chinese Characters to the Hello World.txt file, but those characters are not showing up, even in the default DejaVu font that was included.

What do I need to do to make other characters like Japanese, Chinese, Korean show up?

zeckdude
  • 15,877
  • 43
  • 139
  • 187
  • Does the PDF have this font embedded? Can you check this (via the Document Properties)? Also, check if it is try to substitute the fonts or not (when you open the PDF in a viewer). – dirkgently Aug 21 '10 at 04:05
  • tFPDF "embeds only the necessary parts of the fonts that are used in the document, making the file size much smaller than if the whole fonts were embedded". It is trying to substitute the font and is only showing squares in its place right now. – zeckdude Aug 21 '10 at 05:15
  • Font embedding/substituting is irrelevant if the API doesn't support the necessary codepages required to encode that characters that you're adding to the document. – Rowan Aug 21 '10 at 22:43
  • You'll need to make sure your font actually contains the characters you want (i.e., Helvetica does not contain the Chinese utf-8 range, etc.). Take a look at my fuller answer here: https://stackoverflow.com/a/56429391/2430549 – HoldOffHunger Jun 04 '19 at 16:23

2 Answers2

2

The API that you're using needs to provide specific support for encoding the unicode characters that you're trying to add to the document. This is done by way of a codepage / charset for those characters. There are a number of different charsets available for Japanese, Chinese and Korean characters such as Hangeul, GB2312, Chinese Big 5, Shift JIS, etc.

The API that you're using needs to support the charset that matches the text which you're trying to add.

It looks like FPDF supports some Chinese codepages since there's some info on their forum about adding text using GB2312 and Chinese Big 5, but as they don't appear to mention unicode on their main pages, my guess is that they don't provide extensive support for it.

Rowan
  • 2,384
  • 2
  • 21
  • 22
  • I did get it to work using the font Arial Unicode. The font that the example uses doesn't support CJK characters. – zeckdude Aug 23 '10 at 04:15
2

There is a multi byte version of fpdf called mbfpdf (freely available I suppose). With that and the PGOTHIC font, it is possible to display Asian characters. I have used this class (mbfpdf) to create a few pdf files myself and it worked well.

shawndreck
  • 2,039
  • 1
  • 24
  • 30