pdf_load_font()函数,致命错误

发布于 2024-11-28 19:14:29 字数 853 浏览 5 评论 0原文

<?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”,消息为“字体” 编码为“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} 抛出 C:\xampp\htdocs\test\pdf.php 第 8 行

<?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);  
?>

I found this code in internet, just to observe how PDFLib works. But, it gives me the error below:

Fatal error: Uncaught exception 'PDFlibException' with message 'Font
'Arial' with encoding 'host': Font file (AFM, PFM, TTF, OTF etc.) or
host font not found' in C:\xampp\htdocs\test\pdf.php:8 Stack trace: #0
C:\xampp\htdocs\test\pdf.php(8): pdf_load_font(Resource id #2,
'Arial', 'host', 'embedding=true') #1 {main} thrown in
C:\xampp\htdocs\test\pdf.php on line 8

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喜你已久 2024-12-05 19:14:29

我认为 PDFLib 默认情况下不会查看 Windows 的字体目录,这里是建议:

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

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

I think PDFLib does not look at the windows' fonts directory by default, here is the suggestion:

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

Then, you can set the font with pdf_setfont().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文