首页 > 解决方案 > 从 html 创建 pdf 时字体加倍

问题描述

我正在使用 node.js 构建一个 Web 应用程序,它应该从给定的 HTML 片段创建一个 pdf。

为此,我正在使用 html-pdf 包。除了一种粗体字体外,一切正常。当使用这个字体粗细为 900 的字体时,看起来字体加倍了偏移量。您可以在图片中看到效果(尤其是在“3”处)。

我的 CSS 代码如下所示:

@font-face {
    font-family: 'Proxima Nova Condensed';
    src: url("/fonts/ProximaNovaCond-Regular.ttf") format("truetype");
    font-weight: 400; 
}
@font-face {
    font-family: 'Proxima Nova Condensed';
    src: url("/fonts/ProximaNovaCond-Bold.ttf") format("truetype");
    font-weight: 700; 
}
@font-face {
    font-family: 'Proxima Nova Condensed';
    src: url("/fonts/ProximaNovaCond-Extrabold.ttf") format("truetype");
    font-weight: 800; 
}
@font-face {
    font-family: 'Proxima Nova Condensed';
    src: url("/fonts/ProximaNovaCond-Black.ttf") format("truetype");
    font-weight: 900; 
}

在 Web 应用程序中这有效,但是在生成 pdf 时我遇到了这个问题。

谁能帮我这个?

带偏移量的双倍字体

标签: cssnode.jsfontshtml-pdf

解决方案


你可以尝试添加font-style吗?

https://www.w3schools.com/cssref/pr_font_font-style.asp


推荐阅读