Node-html-pdf: TWO PAGE PDF GENERATED

Created on 2 Jun 2017  路  15Comments  路  Source: marcbachmann/node-html-pdf

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.

Most helpful comment

Adding viewport height to the body resolved my issue

body {
height:100vh;
}

All 15 comments

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

\n" +
"
\n" +
" Certificate of Completion\n" +
"

\n" +
" This is to certify that\n" +
"

\n" +
" "+user.local.name+"

\n" +
" has completed the course

\n" +
" "+course.course_name+"

\n" +
" an online course offered through AMP Digital



\n" +
" dated
\n" +
" #set ($dt = $DateFormatter.getFormattedDate($grade.getAwardDate(), \"MMMM dd, yyyy\"))\n" +
" $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,

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tashikomaaa picture tashikomaaa  路  5Comments

antiframes picture antiframes  路  4Comments

tsp1996 picture tsp1996  路  5Comments

aminjoharinia picture aminjoharinia  路  4Comments

RodolfoSilva picture RodolfoSilva  路  3Comments