【问题标题】:Wkhtmltopdf seems to embed fonts in the PDF in an unpredictable waywkhtmltopdf 似乎以不可预知的方式在 PDF 中嵌入字体
【发布时间】:2017-02-09 08:16:50
【问题描述】:

我开发了一个使用 wkhtmltopdf 生成 PDF 的小型引擎。

在我的 PC (Fedora 24) 上工作时,生成的 PDF 看起来不错。在测试服务器(CentOS 7)上安装软件后,发现生成的PDF略有不同。

我正在使用该工具的独立(未通过包管理器安装)版本。更准确地说,我使用的是 wkhtmltopdf 0.12.3 版本(带有修补的 qt)

经过一番调查,我注意到在我的系统上生成的 PDF 包含以下字体:

在服务器上生成的 PDF 包含以下内容:

在 CSS 中,我将这些字体用于整个文档:

/* open-sans-300 - latin */
@font-face {
    font-family: 'Open-Sans-Light';
    font-style: normal;
    font-weight: 300;
    src: url('../fonts/open-sans-v13-latin-300.eot'); /* IE9 Compat Modes */
    src: local('Open Sans Light'), local('OpenSans-Light'),
    url('../fonts/open-sans-v13-latin-300.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
    url('../fonts/open-sans-v13-latin-300.woff2') format('woff2'), /* Super Modern Browsers */
    url('../fonts/open-sans-v13-latin-300.woff') format('woff'), /* Modern Browsers */
    url('../fonts/open-sans-v13-latin-300.ttf') format('truetype'), /* Safari, Android, iOS */
    url('../fonts/open-sans-v13-latin-300.svg#OpenSans') format('svg'); /* Legacy iOS */
}

/* open-sans-regular - latin */
@font-face {
    font-family: 'Open-Sans-Regular';
    font-style: normal;
    font-weight: 400;
    src: url('../fonts/open-sans-v13-latin-regular.eot'); /* IE9 Compat Modes */
    src: local('Open Sans'), local('OpenSans'),
    url('../fonts/open-sans-v13-latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
    url('../fonts/open-sans-v13-latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
    url('../fonts/open-sans-v13-latin-regular.woff') format('woff'), /* Modern Browsers */
    url('../fonts/open-sans-v13-latin-regular.ttf') format('truetype'), /* Safari, Android, iOS */
    url('../fonts/open-sans-v13-latin-regular.svg#OpenSans') format('svg'); /* Legacy iOS */
}

/* open-sans-300italic - latin */
@font-face {
    font-family: 'Open-Sans-Light-Italic';
    font-style: italic;
    font-weight: 300;
    src: url('../fonts/open-sans-v13-latin-300italic.eot'); /* IE9 Compat Modes */
    src: local('Open Sans Light Italic'), local('OpenSansLight-Italic'),
    url('../fonts/open-sans-v13-latin-300italic.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
    url('../fonts/open-sans-v13-latin-300italic.woff2') format('woff2'), /* Super Modern Browsers */
    url('../fonts/open-sans-v13-latin-300italic.woff') format('woff'), /* Modern Browsers */
    url('../fonts/open-sans-v13-latin-300italic.ttf') format('truetype'), /* Safari, Android, iOS */
    url('../fonts/open-sans-v13-latin-300italic.svg#OpenSans') format('svg'); /* Legacy iOS */
}

/* open-sans-700 - latin */
@font-face {
    font-family: 'Open-Sans-Bold';
    font-style: normal;
    font-weight: 700;
    src: url('../fonts/open-sans-v13-latin-700.eot'); /* IE9 Compat Modes */
    src: local('Open Sans Bold'), local('OpenSans-Bold'),
    url('../fonts/open-sans-v13-latin-700.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
    url('../fonts/open-sans-v13-latin-700.woff2') format('woff2'), /* Super Modern Browsers */
    url('../fonts/open-sans-v13-latin-700.woff') format('woff'), /* Modern Browsers */
    url('../fonts/open-sans-v13-latin-700.ttf') format('truetype'), /* Safari, Android, iOS */
    url('../fonts/open-sans-v13-latin-700.svg#OpenSans') format('svg'); /* Legacy iOS */
}

那么为什么 wkhtmltopdf 会嵌入额外的字体呢?

如何确保 wkhtmltopdf 仅使用 Open Sans 并且无论我在哪个系统上运行该软件都可以获得相同的 PDF?

现在,除了我指定的字体之外,它似乎会随机选择系统中可用的字体:|

【问题讨论】:

    标签: css qt pdf fonts wkhtmltopdf


    【解决方案1】:

    在 Windows 上,我的情况正好相反:在开发机器上,字体可以很好地嵌入到 PDF 中,但在其他机器(例如生产服务器)上,字体丢失并且没有嵌入。 我调查了日志文件,并在生成 PDF 时按预期从机器正确下载了所有字体。 作为最后的手段,我在服务器系统上安装了所有字体(通过控制面板)。这解决了问题.... 我认为这与系统上安装的字体不同有关。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-14
      • 1970-01-01
      • 1970-01-01
      • 2010-10-12
      • 2015-02-16
      相关资源
      最近更新 更多