我正在使用 wkhtmltopdf 生成我的 pdf 文件。我有我正在渲染的主页和页脚页面。它们在单独的视图中。
打印的问题是只加载了字体而没有加载其他字体。
我以相同的方式完成了主页,并且所有 css 都已正确加载。
我对 footer.html.twig 的看法
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Statement Footer</title>
<link href="https://fonts.googleapis.com/css?family=Courier+Prime&display=swap" rel="stylesheet">
</head>
<style type="text/css">
html {
height: 0;
background-color: white;
white-space: nowrap;
font-family: 'Courier Prime', monospace;
}
hr {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #ccc;
margin: 1em 0;
padding: 0;
}
#footer{
display:table-cell;
width:33.33vw;
text-align: center;
}
</style>
<body>
<hr/>
<div id="footer">
Hello!
</div>
</div>
</body>
</html>
在我的控制器中:
$options = [
'encoding' => 'UTF-8',
'footer-html' => $footerHtml = $this->renderView('@WebsiteTemplates/invoice/footer.html.twig')
];
$html = $this->renderView('@WebsiteTemplates/invoice/invoice.html.twig');
$filename = sprintf('test-%s.pdf', date('Y-m-d'));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html, $options),
200,
[
'Content-Type' => 'application/pdf',
'Content-Disposition' => sprintf('attachment; filename="%s"', $filename),
]
);
样式标签很好,我没有 css 文件作为我必须包含的资产。他们都直接在树枝上。