Special Characters in FPDF with PHP

前端 未结 8 1947
陌清茗
陌清茗 2020-12-05 00:16

I have a web form that users can fill out and that content fills up a PDF with FPDF and PHP. When a user enters a word with an apostrophe, a slash appears before it on the P

8条回答
  •  温柔的废话
    2020-12-05 00:35

    none of above solutions worked for me, so I solved the problem like this:

    $this->AddFont('Arial','','arial.php');
    $this->SetFont('Arial','',12);
    $this->Cell(0,5,iconv("UTF-8", "CP1250//TRANSLIT", $string),0,1,'L');
    

    Before trying the above lines, do the following:

    Copy from c:/Windows/Fonts/Arial.ttf to the /tutorial folder of FPDF.

    Edit the content of makefont.php

    require('../makefont/makefont.php');
    MakeFont('arial.ttf','cp1250');
    

    Execute makefont.php

    Copy the following files to the /font folder of FPDF: arial.php arial.ttf arial.z

    Finally, define the "font folder". Open fpdf.php (main library file) and add:

    define('FPDF_FONTPATH','font');
    

    The PDF works for me with all special characters, I believe it was the problem in the Arial font itself, which FPDF originally uses. It should work with other fonts aswell, if they support your characters. Good luck!

提交回复
热议问题