节点幻像显示生成的PDF页面的数量

我正在面临的问题,以获得生成的PDF页面的数量phantomjs。 基本上我用nodejs使用phantomjs,我想在第5页显示总页数。

function generatePdf() { // Load ejs template fs.readFile(__dirname + '/../pdf' + pdfpath, 'utf8', function (err, data) { var fileName = __dirname + '/pdfdata/' + f.formType + f.formId + '.pdf'; // Render the page to variable. var html = ejs.render(data, pdfJSON); fs.writeFile(__dirname + '/pdfdata/test.html', html, function (err) { if (err) throw err; }); // Set this html as the content for the pdf file. page.set('content', html); //page.set( 'paperSize', { width: 1200, height: 1500} ); page.set('paperSize', { //format: 'A4', width: 1200, height: 1600, header: { height: "1cm", contents: "function(pageNum, numPages) { return '<h6 style=text-align:right></h6>'; }" }, footer: { height: "1cm", contents: "function(pageNum, numPages) { return '<h6 style=text-align:right;margin-right:60px;postion:absolute;margin-bottom:-20px>' + pageNum + '</h6>'; }" } }, function () { page.open(__dirname + '/pdfdata/test.html', function () { page.render(fileName, cb); ph.exit(); // Response to client. function cb() { res.jsonp(200, responseJSON); } }) }); }); } // end of function 

为了显示我在generatePdf function添加的页面

 contents: "function(pageNum, numPages) { return '<h6 style=text-align:right;margin-right:60px;postion:absolute;margin-bottom:-20px>' + pageNum + '</h6>'; }" 

并添加到bridge.js

 case 'pageSet': eval('request[4].header.contents = phantom.callback(' + request[4].header.contents + ')'); eval('request[4].footer.contents = phantom.callback(' + request[4].footer.contents + ')'); page[request[3]] = request[4]; respond([id, cmdId, 'pageSetDone']); break; 

如何显示特定页面内生成的页面数量?

为什么不login页面的页面内容,然后显示NumPages。 像这样的东西:

 contents: "function(pageNum, numPages) { if(pageNum === numPages) return '<h6>' + numPages + '</h6>'; else return '<h6>' + pageNum + '</h6>'; }"