I'm not able to install jsPDF on my nodejs with npm. I ran npm install node-jspdf
to work with nodejs, but it does not install because it gives trouble to run install.sh
. Even specifying the package version gives problem. So I downloaded the zip of node-jspdf (indicated in file install.sh
), unpacked it and created the necessary folders, indicated in the same installation file. When running the app the module is not found. But I was able to generate a PDF by referencing the module directly, but I do not know if this works for later:
SO THE APP WORKED IN PRINCIPLE:
var fs = require('fs');
var path = './jsPDF/';
jsPDF = require(path + 'jspdf');
var doc = new jsPDF();
doc.text('Hello world!', 10, 10);
fs.writeFile('teste.pdf', doc.output());
PDF is created correctly in the local folder. But I want to get it sent to the browser. But if I use the Githud example, the following error appears: "navigator is not defined":
SO THE APP DONE ERROR
var fs = require('fs');
var path = './jsPDF/';
jsPDF = require(path + 'jspdf');
var doc = new jsPDF();
doc.text('Hello world!', 10, 10);
doc.save('Test.pdf', function(err){console.log('saved!');}); // <<<<<<==== Gera o erro
Questions: 1) Can I use jspdf indicating the module path directly and saving the file the way it worked? 2) Is not this "navigator is not defined" error because I'm just running a script? I imagine that if running via browser will stop the problem ...