繁体   English   中英

"wkhtmltopdf 似乎以不可预知的方式在 PDF 中嵌入字体"

[英]Wkhtmltopdf seems to embed fonts in the PDF in an unpredictable way

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

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

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

经过一番调查,我注意到在我的系统上生成的 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 */
}

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

"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM