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();
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();
Share
Improve this question
asked Jun 1, 2016 at 13:09
user3193324user3193324
1031 gold badge1 silver badge4 bronze badges
3
|
1 Answer
Reset to default 16You 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.
fs.createWriteStream
in the browser? – robertklep Commented Jun 1, 2016 at 13:16