0

This is my sample.js code wherein if i run this code the pdf will be generated. im trying to look in the internet where the pdf will be generated only if the button for generating pdf will be clicked. but i cannot find how to do it. this is the only code that i have please help me thank you. the button must be in html tho

var pdf = require('pdfkit');
var fs = require('fs');

var myDoc = new pdf;

myDoc.pipe(fs.createWriteStream('node.pdf'));

myDoc.font('Times-Roman')
    .fontSize(48)
    .text('Hello World', 100, 100);

myDoc.end();
mgarcia
  • 5,669
  • 3
  • 16
  • 35
Erfamae Fermo
  • 89
  • 2
  • 7
  • You can use a template engine like EJS for HTML and then you have to link that button click to some route in your App. – Prabhjot Singh Kainth Feb 20 '20 at 11:12
  • https://stackoverflow.com/questions/18831783/how-to-call-a-server-side-function-from-client-side-e-g-html-button-onclick-i – Prabhjot Singh Kainth Feb 20 '20 at 11:13
  • This is server-side / nodeJS code. To run that code after a user clicks a button, you need to run a web server with node and have it create, then send the PDF. In the browser, you need to link to the according URL. –  Feb 20 '20 at 11:13

0 Answers0