2017-08-23 12:47
浏览 103


I have an issue with displaying what ever on a PDF file when I change the font.

include $_SERVER['DOCUMENT_ROOT'] . "/library/fpdf.php";
$pdf = new FPDF('P',"mm",'A4');
foreach ($_SESSION['settings'] as $settings) {


I tried changing the font with other files and I just keep getting random errors like:

Warning: Unexpected character in input:


Parse error [my path to the ttf file]

Even if I don't print anything in the PDF just leave it blank , I still get an error due to the AddFont,

If I remove


and replace it with


it works fine.

图片转代码服务由CSDN问答提供 功能建议

我在更改字体时显示PDF文件的内容时遇到问题。 &lt;?php session_start(); include $ _SERVER ['DOCUMENT_ROOT']。 “/library/fpdf.php"; pdpdf = new FPDF('P',”mm“,'A4'); $ pdf-&gt; AddPage(); $ pdf-&gt; AddFont( 'DejaVu','','DejaVuSans-Bold.ttf',true); $ pdf-&gt; SetFont('DejaVu','',14); foreach($ _SESSION ['settings'] as $ settings ){ $ pdf-&gt; Cell(130,5,$ settings,1,1); } $ pdf-&gt; Output(); ?&gt;


警告:输入中出现意外字符 :

解析错误[我的ttf文件路径] \ n


如果 我删除了

  $ pdf-&gt; AddFont('DejaVu','','DejaVuSans-Bold.ttf',true); 
 $ pdf-&gt; SetFont(  'DejaVu','',14); 


  $ pdf-&gt;  SetFont('Arial','',14); 


  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douang1243 2017-08-23 13:22

    The AddFont function requires a particular type of file to be able to use the font, not just the font file itself. If you take the DejaVuSans-Bold.ttf file and upload it here, it will convert it into the required format for you.

    There will be 2 files generated, DejaVuSans-Bold.php and DejaVuSans-Bold.z. Copy both of these into your project, and then change the line of code to the following:


    There's more information on how to add new fonts on the following tutorial. It has details on how to generate the font files manually on your own PC, however there is an online tool (linked above) that will do it for you:

    Finally, for TrueType and OpenType fonts, you can also generate the files online instead of doing it manually.

    Note: you may get some warnings when you convert online, saying certain characters are missing. If you scroll to the bottom, the converted files will still be available to download, you just won't be able to use any of the listed missing characters in your PDF.

    打赏 评论

相关推荐 更多相似问题