pdf_load_font()函数,致命错误
<?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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 PDFLib 默认情况下不会查看 Windows 的字体目录,这里是建议:
然后,您可以使用 pdf_setfont() 设置字体。
I think PDFLib does not look at the windows' fonts directory by default, here is the suggestion:
Then, you can set the font with pdf_setfont().