【发布时间】:2018-08-19 00:08:10
【问题描述】:
我需要将一个页面呈现为包含 Material 图标的 PDF 文件,但它似乎不起作用。
templates/pdf.html
<html>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<style>
* {
font-family: Roboto, Helvetica, sans-serif;
}
</style>
</head>
<body>
Just test
<i class="material-icons">remove_red_eye</i>
</body>
</html>
gen.py
import pdfkit
from django.template.loader import render_to_string
html = render_to_string('pdf.html')
pdfkit.from_string(html, 'out.pdf')
# I tried this version but it doesn't work either
# pdfkit.from_string(html, 'out.pdf', css=['https://fonts.googleapis.com/icon?family=Material+Icons'])
out.pdf 仅包含文本 Just test。有机会解决吗?
我刚刚还在 pdfkit 存储库中创建了这个问题 - issue
【问题讨论】:
-
html看起来像什么?我的意思是像 print(html) -
如果您使用的是 django.. 尝试
django-easy-pdf.. 看看这里(第二个答案)... 如果它不起作用,请告诉我,我会看看但我认为它会在这种情况下帮助你stackoverflow.com/questions/45233906/… -
也遇到了同样的问题。我只是想办法让它工作。将在下面添加答案