0

我一直在使用PHP WkHtmlToPdf,我在 html 中使用的字体之一是 Century Gothic。在我的开发机器(windows 7 上的 wamp)上,这很好并且显示完美,但是当把它放在 windows server 2007 机器上时,生成 pdf 时不会显示 Century Gothic。

我检查了Century Gothic 是否安装了,我没有安装它,但不幸的是它没有任何区别。

任何帮助将不胜感激。

4

1 回答 1

0

要使用自定义字体创建 PDF 文件,只需在模板的 CSS 部分中指定它们。

我的项目根文件夹的示例(因此它适用于 Windows 和 linux):

$root = 'file://' . (System::isWindows() ? '/' : '') . str_replace('\\', '/', ROOT_PATH);
# windows output : file:///P:/www/project/
# linux output   : file:///var/usr/www/project/

变量$root分配给模板,在这里我使用 CSS 来指定我想要使用的字体(将您使用的字体放入项目中,不要依赖系统字体):

<style type="text/css">
    @font-face {
        font-family: 'FONT_LOCAL';
        src: url('<?= $root ?>font/open_sans_regular.ttf') format('truetype');
        font-weight: normal;
        font-style: normal;
    }
    body, body * {
        margin: 0;
        padding: 0;
        font-family: 'FONT_LOCAL';
        font-size: 14px;
        line-height: 24px;
    }
</style>

对我来说这是最好的解决方案,因为 PDF 文件仅使用这种字体生成,没有您甚至不使用的标准字体,这意味着更小的 PDF 文件。

于 2013-08-16T09:08:50.173 回答