Richard Diogo
Richard Diogo

Reputation: 11

Cordova jsPDF - PDF generated,I can not find the pdf file in Mobile

I'm running in cordova android device, I can get to the line 'console.log ("write success");' but I do not think the file does not appear where it is saved.

I've tried running in 2 different androids, create a pdf file and save in any folder anywhere

The source code http://www.tricedesigns.com/2014/01/08/generating-pdf-inside-of-phonegap-apps/

    //FIRST GENERATE THE PDF DOCUMENT
console.log("generating pdf...");
var doc = new jsPDF();

doc.text(20, 20, 'HELLO!');

doc.setFont("courier");
doc.setFontType("normal");
doc.text(20, 30, 'This is a PDF document generated using JSPDF.');
doc.text(20, 50, 'YES, Inside of PhoneGap!');

var pdfOutput = doc.output();
console.log( pdfOutput );

//NEXT SAVE IT TO THE DEVICE'S LOCAL FILE SYSTEM
console.log("file system...");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {

   console.log(fileSystem.name);
   console.log(fileSystem.root.name);
   console.log(fileSystem.root.fullPath);

   fileSystem.root.getFile("test.pdf", {create: true}, function(entry) {
      var fileEntry = entry;
      console.log(entry);

      entry.createWriter(function(writer) {
         writer.onwrite = function(evt) {
         console.log("write success");
      };

      console.log("writing to file");
         writer.write( pdfOutput );
      }, function(error) {
         console.log(error);
      });

   }, function(error){
      console.log(error);
   });
},
function(event){
 console.log( evt.target.error.code );

Thanks!!

Upvotes: 1

Views: 2718

Answers (1)

Philomath
Philomath

Reputation: 1163

My issue was sorted

Opening a PDF in cordova javascript

jsPDF and cordova Cant view the pdf file

I was trying to write the file to root and access it from there which is not possible in a non rooted phone.

Upvotes: 0

Related Questions