在 Mac (El Capitan) 上使用 PDFLib 中的格鲁吉亚字体

Using Georgia Font in PDFLib on a Mac (El Capitan)

我正在使用 PDFLib 创建 PDF 文件,不幸的是,我似乎无法使用 Georgia 文件。除了那个字体,我几乎可以使用任何其他字体。

我试过加载文件,也试过更改搜索路径,但似乎仍然无效。到目前为止我尝试了什么:

$searchPath = "/Library/Fonts";
$p->set_option("searchpath= {" . $searchPath . "}");
$scoreFont = $p->load_font("Georgia", "unicode", "");
if ($scoreFont == 0){
    die("Error: " . $p->get_errmsg());
}

每当我包含这个时,它都会给我一个 "Page is not working" 错误。

我不确定它是否相关,但我确实在 Library/Font 目录中看到了 Georgia.ttf 文件,但在 System/Library/Font 目录中没有看到。有人对这个问题有任何经验吗?任何帮助将不胜感激。

提前致谢!

编辑

我检查了我的 Apache 日志,发现有一个错误,列为:

Tue Aug 09 11:23:48 2016] [notice] child pid 11501 exit signal Segmentation fault (11)

此外,我检查了 PDFLib 日志文件,我看到:

PDF_load_font[----------------------------------------------------------------   --------------]
[ PDFlib 9.0.5  PHP5 binding on Mac OS X-10.6 64 (le) 2016-08-09 11:23:48      ]
[ Classes: api=1 warning=1                                                     ]
[ Enter in vi to compile it:                                                   ]
[ %s/)$/);/g   and   %s/"(NULL)"/NULL/g   and   %s/\[[^]]*\]//g                ]
[ Program should run on a little-endian platform                               ]
[------------------------------------------------------------------------------]

PDF_set_option(p_0x1097619a8, "searchpath= {/Library/Fonts}")
[New category:resource "SearchPath:/usr/local/PDFlib"]
[New category:resource "SearchPath:/usr/local/PDFlib/PDFlib"]
[New category:resource "SearchPath:/usr/local/PDFlib/PDFlib/9.0"]
[New category:resource "SearchPath:/usr/local/PDFlib/PDFlib/9.0/resource/cmap"]
[New category:resource   "SearchPath:/usr/local/PDFlib/PDFlib/9.0/resource/codelist"]
[New category:resource "SearchPath:/usr/local/PDFlib/PDFlib/9.0/resource/fonts"]
[New category:resource "SearchPath:/usr/local/PDFlib/PDFlib/9.0/resource/glyphlst"]
[New category:resource "SearchPath:/usr/local/PDFlib/PDFlib/9.0/resource/icc"]
[New category:resource "SearchPath:/Users/{username}/PDFlib"]
[New category:resource "SearchPath:/Users/{username}/PDFlib/PDFlib"]
[New category:resource "SearchPath:/Users/{username}/PDFlib/PDFlib/9.0"]
[New category:resource "SearchPath:/Users/{username}/PDFlib/PDFlib/9.0/resource/cmap"]
[New category:resource "SearchPath:/Users/{username}/PDFlib/PDFlib/9.0/resource/codelist"]
[New category:resource "SearchPath:/Users/{username}/PDFlib/PDFlib/9.0/resource/fonts"]
[New category:resource "SearchPath:/Users/{username}/PDFlib/PDFlib/9.0/resource/glyphlst"]
[New category:resource "SearchPath:/Users/{username}/PDFlib/PDFlib/9.0/resource/icc"]
[New category:resource "SearchPath:/Library/Fonts"]

我不确定这些条目的真正含义。在 PDFLib 日志中,唯一实际存在的目录是最后一个,即 /Library/Fonts 那个。在该目录中是 Georgia.ttf 文件。

有什么想法吗?

谢谢!

使用上述代码和 OSX 上的当前 PDFlib 9.0.7 进行快速测试工作正常。因此,检查 webserver/PHP 的错误日志文件可能是个好主意。也许您的网络服务器没有正确给出 die() 案例中的消息。

当您在网络服务器日志文件中没有看到任何错误原因时,您可以启用 PDFlib 日志记录,

$p->set_option("logging {filename {/tmp/PDFlib.log}}");

作为您的第一个 PDFlib 调用。然后你应该看到,如果 load_font() 失败 (0) 和可能的错误消息。

编辑:感谢您分享日志文件中的更多详细信息。条目

Tue Aug 09 11:23:48 2016] [notice] child pid 11501 exit signal Segmentation fault (11)

可能是关于 Mac 上的 HostFont 问题以及 PHP 和网络服务器的指示。你能禁用主机字体支持吗?在 PDFlib PHP 示例中,此调用已被注释掉,因此启用调用非常简单:

 /* Enable the following line if you experience crashes on OS X
  * (see PDFlib-in-PHP-HowTo.pdf for details):
  */
  $p->set_option("usehostfonts=false");