title: Nodejs how to generate a pdf file from ejs file
body: <p>I'm writing a nodejs method which I want to convert an ejs file to a pdf file</p>
  <pre><code>router.get(&quot;/uknow&quot;, (req, res) =&gt; {
      ejs.renderFile(path.join(__dirname, &quot;../../views/resultat.ejs&quot;),  (err, data) =&gt; {
      if (err) {
            res.send(err);
      } else {
          
          pdf.create(data).toFile(&quot;report.pdf&quot;, function (err, data) {
              if (err) {
                  res.send(err);
              } else {
                  res.send(&quot;File created successfully&quot;);
              }
          });
      }
  });
  })
  </code></pre>
  <p>this is the method which I wrote and I get this response in post man</p>
  <pre><code>{
      &quot;path&quot;: &quot;C:\\Users\\HP\\Desktop\\exemple CRUD\\blog_api\\views\\resultat.ejs&quot;
  }
  </code></pre>
  <p>i print the error and this is what i get ReferenceError:</p>
  <pre><code>C:\Users\HP\Desktop\exemple CRUD\blog_api\views\resultat.ejs:41
      39| &lt;/head&gt;
      40| &lt;body class=&quot;spacer&quot;&gt;
   &gt;&gt; 41|     &lt;h2 class=&quot;text-center my-3&quot;&gt;&lt;%= data[0].imei.name %&gt;&lt;/h2&gt;
      42|     &lt;h5 class=&quot;text-center my-3&quot;&gt;Imei -&lt;%= data[0].imei.name %&gt; &lt;/h5&gt;
      43|     &lt;h3 class=&quot;text-center my-3&quot;&gt;Resultat des tests&lt;/h3&gt;
      44|     &lt;hr&gt;
  
  data is not defined
      at eval (eval at compile (C:\Users\HP\Desktop\exemple CRUD\blog_api\node_modules\ejs\lib\ejs.js:661:12), &lt;anonymous&gt;:10:26)
      at resultat (C:\Users\HP\Desktop\exemple CRUD\blog_api\node_modules\ejs\lib\ejs.js:691:17)
      at tryHandleCache (C:\Users\HP\Desktop\exemple CRUD\blog_api\node_modules\ejs\lib\ejs.js:272:36)
      at Object.exports.renderFile (C:\Users\HP\Desktop\exemple CRUD\blog_api\node_modules\ejs\lib\ejs.js:489:10)
      at C:\Users\HP\Desktop\exemple CRUD\blog_api\routes\apis\post.js:121:9
      at Layer.handle [as handle_request] (C:\Users\HP\Desktop\exemple CRUD\blog_api\node_modules\express\lib\router\layer.js:95:5)
      at next (C:\Users\HP\Desktop\exemple CRUD\blog_api\node_modules\express\lib\router\route.js:137:13)
      at Route.dispatch (C:\Users\HP\Desktop\exemple CRUD\blog_api\node_modules\express\lib\router\route.js:112:3)
      at Layer.handle [as handle_request] (C:\Users\HP\Desktop\exemple CRUD\blog_api\node_modules\express\lib\router\layer.js:95:5)
      at C:\Users\HP\Desktop\exemple CRUD\blog_api\node_modules\express\lib\router\index.js:281:22
      at Function.process_params (C:\Users\HP\Desktop\exemple CRUD\blog_api\node_modules\express\lib\router\index.js:335:12)
      at next (C:\Users\HP\Desktop\exemple CRUD\blog_api\node_modules\express\lib\router\index.js:275:10)
      at Function.handle (C:\Users\HP\Desktop\exemple CRUD\blog_api\node_modules\express\lib\router\index.js:174:3)
      at router (C:\Users\HP\Desktop\exemple CRUD\blog_api\node_modules\express\lib\router\index.js:47:12)
      at Layer.handle [as handle_request] (C:\Users\HP\Desktop\exemple CRUD\blog_api\node_modules\express\lib\router\layer.js:95:5)
      at trim_prefix (C:\Users\HP\Desktop\exemple CRUD\blog_api\node_modules\express\lib\router\index.js:317:13) {
    path: 'C:\\Users\\HP\\Desktop\\exemple CRUD\\blog_api\\views\\resultat.ejs'
  }
  </code></pre>
  <p>and nothing in the console. I need some help.</p>