HTML& pdf在wkhtmltopdf中有所不同

发布于 2025-01-21 21:45:42 字数 1063 浏览 2 评论 0原文

似乎这个问题已经发布了几次,但是在这里再次发布,因为我找不到任何对我的问题有用的东西:(

我正在使用wkhtmltopdf从HTML视图中生成PDF文件。我在网站中添加了自定义字体。渲染已呈现。 看起来很棒,但CSS样式未正确应用。

HTML

@font-face {
    font-family: 'MyFont';
    src: url('fonts/MyFont-Light.otf') format('opentype'),
    url('fonts/MyFont-Light.ttf') format('truetype');
    font-weight: 300;
    font-style: normal;
}

@font-face {
    font-family: 'MyFont';
    src: url('fonts/MyFont-Regular.otf') format('opentype'),
    url('fonts/MyFont-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
}

body {
    font-family: 'MyFont', Helvetica, Arial, sans-serif;
    font-weight: 300;
}

h1 {
    font-weight: 400;
}

的视图

pdf视图

有人可以帮我解决这个问题吗?提前致谢。

Seems this question has been posted a few times, but posting here again because I couldn't find anything useful for my issue :(

I am using wkhtmltopdf to generate pdf files from HTML views. I have added custom fonts in the site. The rendered HTML view looks great. But the CSS styles aren't applied in the PDF properly.

My CSS

@font-face {
    font-family: 'MyFont';
    src: url('fonts/MyFont-Light.otf') format('opentype'),
    url('fonts/MyFont-Light.ttf') format('truetype');
    font-weight: 300;
    font-style: normal;
}

@font-face {
    font-family: 'MyFont';
    src: url('fonts/MyFont-Regular.otf') format('opentype'),
    url('fonts/MyFont-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
}

body {
    font-family: 'MyFont', Helvetica, Arial, sans-serif;
    font-weight: 300;
}

h1 {
    font-weight: 400;
}

HTML View
enter image description here

PDF View
enter image description here

Can someone please help me resolve this issue? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文