我这里有一个大问题。我想使用 express.js、phantomjs 和 EJS 从带有自定义页眉和页脚的 HTML 模板自动生成 PDF 文件。
我在 PhantomJS 生成的页脚页眉中放置任何“硬编码”HTML 字符串没有任何问题(它们工作):
footer: {
height: "3cm",
contents: ph.callback(function(pageNum, numPages) {
return "<div style='padding: .2em; font-size: 10pt;border-top: 1px solid #ccc; color: #999;'> FOOTER <span style='float:right'> Página " + pageNum + " / " + numPages + "</span></div>";
})
Run Code Online (Sandbox Code Playgroud)
但是,每当我尝试以编程方式对其进行自定义时:
var pdfHeader = ejs.compile(fs.readFileSync(path.join('server/components/mail/html-templates/pdf-header.html'), 'utf8'));
pdfHeader = pdfHeader({info: info});
header: {
height: "3cm",
contents: ph.callback(function(pageNum, numPages) {
if (pageNum == numPages) {
return "";
}
return pdfHeader;
})
}, …Run Code Online (Sandbox Code Playgroud)