Thunder Rabbit
Thunder Rabbit

Reputation: 5449

can't display ¥ with TCPDF, but other kanji are okay

I'm using TCPDF to create PDFs that include Japanese characters. Using the TrueType font ArialUni, most characters are displayed correctly, except the yen symbol shows up as a square box instead of ¥.

Here's a snippet of the resulting PDF using ArialUni:

using ArialUni

So I tried another font. Here's the same section of the resulting PDF using GT200001:

using GT200001

And here's the same section using Helvetica:

using Helvetica

Here's the same section using GNU's FreeSans:

using FreeSans

I would like that second line to show up as "(渋谷猿, ¥8,000)"

I'm not surprised that Helvetica and Freesans cannot render the kanji correctly, but I cannot fathom why the other two fonts can render the kanji, but not the yen symbol, which is much more common.

The web server creating the PDFs is LAMP running Ubuntu. I'm viewing the PDFs on OS X with Chrome (using its in-browser view). I've also tried downloading the PDFs with Firefox and displaying in Preview. I get essentially the same results: ArialUni and GT200001 don't display the yen symbol, while Helvetica and Freesans don't display the kanji (but do display the yen symbol).

I know I can use different fonts for different lines/cells of the PDF, but the kanji and yen symbol are on the same line.

How can I get the kanji and yen symbol to display in a single line using TCPDF?

Near the top of my PDF code, I load the font using TCPDF's addTTFfont();

    $this->font = $this->addTTFfont(K_PATH_FONTS.'arialuni.ttf', 'TrueTypeUnicode', '', 32);

Here's the code I'm using to write the section of the PDF.

        $pdf->SetFont('arialuni','',10);
        $pdf->MultiCell(105, $remarks_height, $remarks, 'B', 'L', false, 0, '', '', true, 1, false, true,  $remarks_height, 'T');

Upvotes: 4

Views: 1827

Answers (3)

Francisco Presencia
Francisco Presencia

Reputation: 8851

In this wikipedia article you can read some more about this character.

Basically, there are 2 different ways of writing this Japanese Kanji, as it happens with some other symbols. From accepted answer "I was using ¥, not ¥", we can see that he was using the 'occidental' or Unicode ¥ symbol, when he actually wanted to use the double-width character ¥.

Upvotes: 5

ATilara
ATilara

Reputation: 531

What I have noticed with TCPDF is, it's all about fonts. I tried to use it for 15 totally different languages with different writing style too and only font I am using is Arial UNICODE MS.

TCPDF has function which will convert that font into TCPDF friendly files, which are arialuni.ctg.z(70k), arialuni.php(447k), and arialuni.z (14M).

the functions are, http://www.tcpdf.org/fonts.php

$fontname = $pdf->addTTFfont('/path-to-font/ARIALUNICODE.TTF', 'TrueTypeUnicode', '', 32);

Upvotes: 2

Thunder Rabbit
Thunder Rabbit

Reputation: 5449

Oh dear, I figured it out.

I was using ¥, not ¥. Sorry for being confused!!

Upvotes: 3

Related Questions