title: make pdf file from jsPDF and send pdf file to server node js
body: <p>i have code to make pdf and succeeded in downloading and opening it, but i want to send pdf to my server on node js, and i have made app.post on server but i can't make pdf become base64 and save it on server</p>
  
  <p>in frontend</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function genPDF() {
          html2canvas(document.getElementById('testDiv')).then(function (canvas) {
              var img = canvas.toDataURL('image/png');
              var doc = new jsPDF('landscape');
              doc.addImage(img, 'png', 10, 10);
              var temp = doc.save('test.pdf');
  
              var post = new XMLHttpRequest();
              post.open("POST", "/receive");
              post.send(temp);
      }
  &lt;/script&gt;
  &lt;a href="javascript:genPDF()"&gt;Download PDF&lt;/a&gt;
  </code></pre>
  
  <p>in server</p>
  
  <pre><code>app.post('/receive', function (request, respond) {
  
  var body = '';
  
  var filePath = './static' + '/document/Document.pdf';
  
  // 
  request.on('data', function (data) {
      body += data;
  });
  
  
  request.on('end', function () {
  
      var data = body.replace(/^data:image\/\w+;base64,/, "");
  
      var buf = new Buffer(data, 'base64');
  
      fs.writeFile(filePath, buf, function (err) {
          if (err) throw err
  
          respond.end();
      });
  });
  </code></pre>
  
  <p>});</p>
  
  <p>how to send <code>var temp = doc.save('test.pdf');</code> server and generate pdf to base64?</p>