Generate PDF Report in Meteor js
<p>I am very close to generate PDF report in Meteor js which will help many folks out there. My code runs almost till the end, but ends up having error </p>

<p><strong>{ [Error: ENOENT, open 'report.pdf'] errno: 34, code: 'ENOENT', path: 'report.pdf' }</strong></p>

<p>Below is code snippet which I am using to generate a PDF list.</p>

<p><strong>Layout.html</strong></p>

<pre><code>&lt;head&gt;
    &lt;style type="text/css"&gt;
        {{css}}
     &lt;/style&gt;
 &lt;/head&gt;
 &lt;body&gt;
      {{&gt; Template.dynamic template=template data=data}}
 &lt;/body&gt;
</code></pre>

<p><strong>report.html</strong></p>

<pre><code>&lt;body&gt;
    &lt;div class="container"&gt;
        {{#each voters}}
            &lt;h4&gt;{{name}}&lt;/h4&gt;&lt;br&gt;
         {{/each}}
    &lt;/div&gt;
&lt;/body&gt;
</code></pre>

<p><strong>server/method.js</strong></p>

<pre><code>var total = voters.find()

Meteor.methods({'generate_pdf': function() {

console.log("--------inside PDF generation Module----------");

var fs      = Npm.require('fs'),
    Future  = Npm.require('fibers/future'),
    fut = new Future(),
    fileName = "report.pdf",
    voters = total,
    data = { voters: voters }

SSR.compileTemplate('layout', Assets.getText('layout.html'));

SSR.compileTemplate('report', Assets.getText('report.html'));

var html_string = SSR.render('layout', { template: "report", data: data });

var options = {
        "paperSize": { "format": "Letter", "orientation": "portrait", "margin": "1cm" },
          siteType: 'html'
};

console.log("------------Commencing webshot-----------");

webshot(html_string, fileName, options, function(err) {
  fs.readFile(fileName, function (err, data) {
     if (err) {
        return console.log(err);
     }

     fs.unlinkSync(fileName);
     fut.return(data);
  });
});

console.log("------------Waiting till PDF generated-----------");   

let pdfData = fut.wait();
let base64String = new Buffer(pdfData).toString('base64');

console.log("------------Return result-----------"); 

return base64String;
 }
});
</code></pre>

<p><strong>Triggerpoint with button : home.html</strong></p>

<pre><code>&lt;template name="home"&gt;
    &lt;div class="container"&gt;
        &lt;div class="row"&gt;
            &lt;div class="col-sm-6 col-sm-offset-3"&gt;
                &lt;a href="#" class="generate-pdf"&gt;Generate PDF&lt;/a&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/template&gt;
</code></pre>

<p><strong>home.js</strong></p>

<pre><code>Template.home.events({
    'click .generate-pdf': function(e, tmpl) {
        e.preventDefault();

        Meteor.call('generate_pdf', function(err, res) {
          if (err) {
                console.error(err);
          } else if (res) {
                window.open("data:application/pdf;base64, " + res);
          }
        })
      }
});
</code></pre>

<p><strong>ERROR LOG ON CONSOLE :</strong></p>

<pre><code>=&gt; Meteor server restarted                    
=&gt; Client modified -- refreshing
I20160509-16:17:04.639(5.5)? --------inside PDF generation Module----------
I20160509-16:17:14.617(5.5)? ------------Commencing webshot-----------
I20160509-16:17:14.622(5.5)? ------------Waiting till PDF generated-----------
I20160509-16:17:14.712(5.5)? { [Error: ENOENT, open 'report.pdf'] errno: 34, code: 'ENOENT', path: 'report.pdf' } 
</code></pre>

<ol>
<li>As per my understanding the error is thrown at line
<strong>fs.readFile(fileName, function (err, data) {</strong>  in file <strong>method.js</strong> </li>
<li>While it is not able to read the file which might not be generated. Can anyone help me out for this, if this case is solved many would be in benefit with ready boiler plate code here.</li>
</ol>