I want to make a pdf file on client-side and afterwards it has to be send server-side through a REST call.
With the generation of the file, I have no problem. I use pdfMake to generate the file and that works fine.
Because I want to send the file to my backend, I have to store the file on the filesystem. To achieve this, I use node.js. The code below works fine. Only when I want to use a function of the object fs, I get the error 'Uncaught TypeError: fs.createWriteStream is not a function'. What am I doing wrong?
var docDefinition = localStorage.getItem('docDefinition');
var PdfPrinter = require('pdfmake');
var printer = new PdfPrinter();
var pdfDoc = printer.createPdfKitDocument(JSON.parse(docDefinition));
var fs = require('fs');
var stream = fs.createWriteStream('basics.pdf');
pdfDoc.pipe(stream);
pdfDoc.end();
You are confusing the server and the client. The browser has no programmatic access to the filesystem. Period. The filesystem api is triggered only via user interaction (like dragging and dropping a file on the webpage). You cannot write a file locally on the client.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With