I have a huge problem . I want to automatically generate PDF files from HTML templates with custom headers and footers using express.js, phantomjs and EJS.
I have no problem installing any “hard-coded” HTML lines in PhantomJS created by footer headers (they work):
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>";
})
But, when I try to configure it programmatically:
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;
})
},
It does not work and gives me this message:
phantom stdout: SyntaxError: Unexpected EOF
How can I put custom HTML with some user data in the header?