我正在使用Ruby on Rails使用WickedPDF生成PDF并通过电子邮件发送。我在两台计算机上有完全相同的代码(代码存储在GitHub上,本地实例是最新的并且完全相同),但是由于任何原因,PDF报告中提供的字体都不相同。一个是Arial,另一个似乎是Verdana。
这是创建PDF的代码:
header_html = av.render(template: "layouts/report_header", locals: {company_name: company_name, layout: nil)
footer_html = av.render(template: "layouts/report_footer", locals: {company_name: company_name, layout: nil)
pdf_html = av.render(:template => "reports/report", locals: {data: data})
body_pdf = WickedPdf.new.pdf_from_string(
pdf_html,
footer: {
content: footer_html
},
header: {
content: header_html
},
margin: {
top: 25,
bottom: 17,
left: 10,
right: 10
},
)
body_path = Rails.root.join("public/#{@project_id}/body.pdf")
File.open(body_path, "wb") do |file|
file << body_pdf
end
pdf_html
的内容(内容主体)显示如下:
<!DOCTYPE html>
<html>
<head>
<style>
p {
color: #545658;
font-size: 12pt;
font-family: "Arial";
font-weight: 500;
}
li {
color: #545658;
font-size: 12pt;
font-family: "Arial";
font-weight: 500;
}
h1 {
color: #ED1C24;
font-weight: normal;
font-family: "Arial";
}
th {
padding-top: 12px;
padding-bottom: 12px;
text-align: center;
background-color: black;
color: white;
}
td {
color: #545658;
padding-top: 5px;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 5px;
}
table.bordered {
border-collapse: collapse;
}
table.bordered td {
border: 1px solid black;
}
table.bordered tr:first-child td {
border-top: 0;
}
table.bordered tr td:first-child {
border-left: 0;
}
table.bordered tr:last-child td {
border-bottom: 0;
}
table.bordered tr td:last-child {
border-right: 0;
}
tr.bordered:nth-child(even) {background-color: #f2f2f2;}
img.finding {
position:absolute;
width:60%;
height: 40px;
margin-left: -20px;
max-width: 100%;
z-index:-1;
}
p.finding {
display: inline;
color: white;
font-weight: bold;
font-size: 16pt;
line-height: 1.75em;
}
pre code {
background-color: #eee;
border: 1px solid #999;
display: block;
padding: 5px;
font-family: "Consolas";
font-size: 10pt;
color: black;
}
</style>
</head>
<body>
<p>Hello world</p>
</body>
</html>
这在一台计算机上可以正常工作,但在另一台计算机上却不能。我觉得这个问题发生在Rails之外。
关于为什么这可能在两台不同的计算机上给我带来不同结果的任何建议?
答案 0 :(得分:1)
wicked_pdf
使用wkhtmltopdf。如果要在所有计算机上获得相同的结果,则wkhtmltopdf
版本必须在所有计算机上都相同。计算机上wkhtmltopdf
的版本可能不相同。
更新
所有计算机必须具有Arial
字体。如果缺少Arial
字体,则可能导致此错误。