node-html-pdf icon indicating copy to clipboard operation
node-html-pdf copied to clipboard

TWO PAGE PDF GENERATED

Open sasankamourya opened this issue 7 years ago • 16 comments

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.

sasankamourya avatar Jun 02 '17 09:06 sasankamourya

Having the same issue

yingliangzhang avatar Jun 09 '17 04:06 yingliangzhang

@marcbachmann Can you please have a look into this issue ?

sasankamourya avatar Jun 09 '17 07:06 sasankamourya

please provide more info. html & config to reproduce would be nice.

marcbachmann avatar Jun 09 '17 11:06 marcbachmann

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 ?

sasankamourya avatar Jun 09 '17 12:06 sasankamourya

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"
  }
}

yingliangzhang avatar Jun 10 '17 09:06 yingliangzhang

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>' } } }

madhavkaneriya avatar Jun 12 '17 07:06 madhavkaneriya

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 avatar Jun 20 '17 01:06 chrisrickard

@chrisrickard Nice, that solved my issue, thanks!

yingliangzhang avatar Jun 20 '17 01:06 yingliangzhang

Thanks @chrisrickard , working for me too!!

madhavkaneriya avatar Jun 20 '17 12:06 madhavkaneriya

Taking out the footer config removed the extra page, but now I don't have a footer. 👀

mossymaker avatar Jun 24 '17 03:06 mossymaker

Adding viewport height to the body resolved my issue

body {
height:100vh;
}

MrunalShidurkar avatar Sep 28 '17 12:09 MrunalShidurkar

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?

Siddharth2212 avatar Nov 01 '18 09:11 Siddharth2212

Adding viewport height to the body resolved my issue

body {
height:100vh;
}

Thank you. Worked for me too,

Ayushverma8 avatar Apr 07 '20 15:04 Ayushverma8

Is there a way to generate one page in PORTRAIT and the next one in LANDSCAPE for the same PDF?

svencoding avatar Apr 16 '20 13:04 svencoding

Adding viewport height to the body resolved my issue

body {
height:100vh;
}

Thank you. Worked for me too,

RexH0 avatar Sep 13 '20 09:09 RexH0

Adding viewport height to the body resolved my issue

body {
height:100vh;
}

Worked for me too

pedrolobo123 avatar Feb 21 '23 13:02 pedrolobo123