node-html-pdf
node-html-pdf copied to clipboard
TWO PAGE PDF GENERATED
Though the HTML was of single page and after converting it into PDF, everything fits in well. But, a single blank page is attached to the PDF file. I don't need the second page. Need help in how to avoid generation of that extra page.
Having the same issue
@marcbachmann Can you please have a look into this issue ?
please provide more info. html & config to reproduce would be nice.
var html = fs.readFileSync(channelConfig.customerInvoicePath+invoiceNumber+'.html', 'utf8');
var options = { header: {contents: '<img src="file:\\\\\var\\V2\\Services\\Node\\billingv2\\invoicetemplates_abtis\\abtis_logo.png" />' }, footer: { contents: { default: '<span style="color: #444;">{{page}}</span>'}}, height: '2000px', width: '1414.227124876255px', border: {top: '1cm', right: '1cm', bottom: '1cm', left: '1cm'}, zoomFactor: '1' };
pdf.create(html, options).toFile(channelConfig.customerInvoicePath+invoiceNumber+'.pdf', function(err, res) {
invoiceDocGenResultObj.orderNumber = invoiceNumber;
invoiceDocGenResultObj.docGenStatus = 'success';
resultArray.push(invoiceDocGenResultObj);
return fulfill(resultArray);
});
}
This is the config file. should i append the html too? I have written it in xml and have parsed it into html. should i append the whole xml file @marcbachmann ?
I'm using handlebars templates, below is html file generated: https://drive.google.com/file/d/0B5CJVwHYW_QOYVNEY1pCTGp0Zlk/view?usp=sharing
and the page setup I'm using:
{
"format": "A4",
"orientation": "portrait",
"border": {
"left": "1cm",
"right": "1cm",
"top": "1cm",
"bottom": "1cm"
},
"header": {
"height": "20mm"
},
"footer": {
"height": "10mm"
}
}
I am also having the same issue, one blank page is attached to the pdf file, and the config I'm using,
{ zoomFactor: 1.0, viewportSize: { width: 1200, height: 1280 }, "border": { "top": "0", "right": "1in", "bottom": "0", "left": "1in" }, "format": "A4", "orientation": "portrait", "footer": { "height": "28mm", "contents": { default: '<span style="font-size:12px;color: #000;text-align:right; display: inline-block; width: 100%;">Page {{page}}</span>' } } }
Hi guys, I had this in the CSS which was causing it for me;
.page {
page-break-after: always;
}
Changing to this fixed it:
.page {
page-break-after: always;
}
.page:last-of-type {
page-break-after: auto
}
@chrisrickard Nice, that solved my issue, thanks!
Thanks @chrisrickard , working for me too!!
Taking out the footer config removed the extra page, but now I don't have a footer. 👀
Adding viewport height to the body resolved my issue
body {
height:100vh;
}
This is my html.
var html = "\n" +
"<div style="width:720px; height:520px; margin-left: 2.5%; padding:20px; text-align:center; border: 10px solid #787878">\n" +
"<div style="width:675px; height:475px; padding:20px; text-align:center; border: 5px solid #787878">\n" +
" <span style="font-size:45px; font-weight:bold">Certificate of Completion\n" +
"
\n" +
" <span style="font-size:22.5px">This is to certify that\n" +
"
\n" +
" <span style="font-size:27px">"+user.local.name+"
\n" +
" <span style="font-size:22.5px">has completed the course
\n" +
" <span style="font-size:27px">"+course.course_name+"
\n" +
" <span style="font-size:18px">an online course offered through AMP Digital
\n" +
" <span style="font-size:22.5px">dated
\n" +
" #set ($dt = $DateFormatter.getFormattedDate($grade.getAwardDate(), "MMMM dd, yyyy"))\n" +
" <span style="font-size:30px">$dt\n" +
"\n" +
""
How can I fix this issue, i.e. where to change CSS?
Adding viewport height to the body resolved my issue
body { height:100vh; }
Thank you. Worked for me too,
Is there a way to generate one page in PORTRAIT and the next one in LANDSCAPE for the same PDF?
Adding viewport height to the body resolved my issue
body { height:100vh; }
Thank you. Worked for me too,
Adding viewport height to the body resolved my issue
body { height:100vh; }
Worked for me too