Creating PDF with Japanese Character

Topics: Developer Forum, Project Management Forum, User Forum
Oct 25, 2010 at 11:02 AM

Hello,

I am new with PHPExcel.

I am having trouble with Saving File as PDF with Japanese character.

I even tried

1. Setting the page font with "MS Mincho" .

2. Setting the cell font with "MS Mincho".

In both case I have got multiple box. But No Japanese Character. Can anyone suggest me about what I am missing?

 

Best Regards,

Johny

Coordinator
Oct 25, 2010 at 11:23 AM
PHPExcel uses tcPDF for generating PDF output from HTML, If you can
confirm that PHPExcel generates HTML output showing the correct
characters, then the problem is that tcPDF doesn't include MS Mincho.
I know that arialunicid0-japanese is included in the font distribution
with tcPDF, so you could always use that instead. Alternatively (I can't
read Japanese, so I can't say for certain) the following link seems to
describe how to add MS Mincho to tcPDF.

http://labs.mythos-jp.com/blog/archives/241

---
Mark Baker
Oct 27, 2010 at 3:56 AM

Mark Baker,

Thank you for your reply.

It had made the HTML very nice. More over  I have avoided the The font issue.

PHPExcel added UTF-8 character set automatically.

But Now the same issue how would I convert it from HTML to PDF or xls to PDF with proper character.

Please let me know

Oct 27, 2010 at 12:07 PM

well,

I have solved the problem. Even though the way i solved is very rough. Need to work more to get a proper solution.

To do so, I have followed the instruction given in

http://labs.mythos-jp.com/blog/archives/241

this link. This link is completely in Japanese. Trust me I dont understand Japanese either. I used google translator to understand it.

To do so, you will need several things.

1. The full font. Download it from internet(I googled MS Mincho. its size was 7.8 MB or something close)

2. download TCPDF.  You may ask "why? its already with PHPExcel.". Yes it is true. But that portion dont have all the tools. It only have required tools that it needed.

3. Now follow the instruction listed in http://labs.mythos-jp.com/blog/archives/241.

     Even though all is described very will, I will give a little discription 

     i)   extract the TCPDF

     ii)  move the dowloaded ttf file to TCPDF/fonts/utils/    directory

     iii) open command promt go to TCPDF directory. in my case it was C Drive root directory(I used it in windows)

     iv) change your directory to TCPDF/fonts/utils/. In my case C:/tcpdf/fonts/utils. (sorry later I found the tools are available :) )IN

           the directory you will get ttf2ufm.exe for windows and ttf2ufm(I guess for linux)

         Now from command prompt use the command below: The font file name was ms-mincho.ttf

     >ttf2ufm.exe -a -F ms-mincho.ttf

     Three file will be generated(in my case i got lots of warnings. I dont know what to do with that). But Its working. so I ignored it.

     there is a php file in the current directory name makefont.php

     Now do the command below

    >[complete path of PHP]\php.exe ms-mincho.ttf ms-mincho.ufm 0

      in my case the path is C:\Program Files\EasyPHP-5.3.3\php\php.exe

     It created a file name ms-mincho.php in the same directory. now you have four file name with ms-mincho without(ms-mincho.ttf)

     Move all the file to [ the installtion directory of PHPExcel ]/Classes/Shared/PDF/fonts/ directory. in my case C:\Program Files\EasyPHP-5.3.3\php\1.7.4\PHPExcel\Shared\PDF\fonts

    But in my system I have moved out PHPExcel directory from Classes. So dont get confused.

   Now, Your font is ready to use.

   PHPExcel is not well defined yet to use font or may I just dont know how to do it. But I have found my own way with my limited knowledge and intelligence.

    Open PHPExcel\Writer\PDF.php with some suitable php editor. Find the line $pdf->SetFont($this->_font) if you print this line for test purpose you will see that the value is showing freesans

   To fix my problem. I did deal with the whole thing. I just change only $pdf->SetFont($this->_font) to $pdf->SetFont('ms-mincho'). It solved my problem. Now I can see the proper japanese in my PDF file.

I did this because I need both xls and pdf file on some certain format so I needed this.

 

If you have better solution please let me know.