pdf_load_font()函数,致命错误

时间:2011-08-06 23:08:24

标签: php pdflib

<?php  
     $pdf = pdf_new();  

     pdf_open_file($pdf, "philosophy.pdf");  

     pdf_begin_page($pdf, 595, 842);  

     $arial = pdf_load_font($pdf, "Arial", "host", "embedding=true"); 
     pdf_setfont($pdf, $arial, 10);  

     pdf_show_xy($pdf, "There are more things in heaven and earth, Horatio,", 50, 750); 
     pdf_show_xy($pdf, "than are dreamt of in your philosophy", 50, 730);  

     pdf_end_page($pdf);  

     pdf_close($pdf);  
?>

我在互联网上找到了这个代码,只是为了观察PDFLib的工作原理。但是,它给出了以下错误:

  

致命错误:未捕获的异常'PDFlibException',消息'Font   编码'host'的'Arial':字体文件(AFM,PFM,TTF,OTF等)或   在C:\ xampp \ htdocs \ test \ pdf.php中找不到主机字体:8堆栈跟踪:#0   C:\ xampp \ htdocs \ test \ pdf.php(8):pdf_load_font(资源ID#2,   'Arial','host','embedding = true')#1 {main}投入   第8行的C:\ xampp \ htdocs \ test \ pdf.php

1 个答案:

答案 0 :(得分:-1)

我认为默认情况下PDFLib不会查看windows的fonts目录,这是建议:

$fontdir = "C:\WINDOWS\Fonts"; 
pdf_set_parameter($pdf, "FontOutline", "arialMyName=$fontdir\arial.ttf");
$arial = PDF_findfont($pdf,"arialMyName","host",0 );

然后,您可以使用pdf_setfont()设置字体。