jspdf download button doesn't do anything when clicked. in android cordova

Muhammad Rauuf

i make an android app with cordova and angularjs. I have made download pdf button and it works fine on my laptop. but when compiled to android, my button doesn't do anything when clicked. i have added plugin cordova plugin add org.apache.cordova.file

i followed tutorial here http://www.tricedesigns.com/2014/01/08/generating-pdf-inside-of-phonegap-apps/ and here my code.

           $scope.exportPDF = function(){       
                    alert("tes");
                    //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 );
                    });
}

the alert is worked, but my pdf still not work. any suggestion?

aWebDeveloper

Do the following

  1. Use your code to generate pdf and store it locally or even better do it server side
  2. Install In-App browser plugin

    cordova plugin add cordova-plugin-inappbrowser
    
  3. Create a download button with

    onclick="window.open("LOCAL_OR_REMOTE_URL", '_system');
    

Not only will this download the pdf it will open the pdf in the browser/pdf app

<button class="btn btn-default" onclick="window.open(PDF_URL, '_system')">
    <i class="fa fa-file-pdf-o"></i> PDF
</button>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

FileLock on Android doesn't do anything?

From Dev

ionic build android doesn't do anything

From Dev

Clicking the top home button doesn't do anything

From Dev

Button in nested fragment doesn't do anything on click

From Dev

UITextField doesn't end editing when Button clicked( delegate textFieldDidEndEditing )

From Dev

Click on button doesn't respond when clicked on text

From Dev

When I select a item it doesn't do anything?

From Dev

gcc doesn't do anything when trying to compile a code

From Dev

Android Listview Doesn't show anything when changing orientation

From Dev

Pacman doesn't download anything - Always 404

From Dev

belongsTo doesn't do anything

From Dev

Maltparser doesn't do anything

From Dev

Jcrop doesn't do anything

From Dev

KeyboardAvoidingView doesn't do anything

From Dev

Android button doesn't change when pressed

From Dev

Android onclicklistener doesn't work the first time when clicked

From Dev

Rails how to download only current record when clicked download button

From Dev

Why doesn't pressing the Next button in iTunes Connect "Start External Testing" page do anything?

From Dev

javascript button doesn't wait for to be clicked

From Dev

how to cancel a download when user clicked in android

From Dev

ArangoDB password doesn't seem to do anything

From Dev

Phonegap CLI on linux doesn't do anything

From Dev

rake db:seed doesn't do anything

From Java

NPM run * doesn't do anything

From Dev

Wix - Superseding patch doesn't do anything

From Dev

OpenMP: parallel for doesn't do anything

From Dev

Why my Aspect doesn't do anything?

From Dev

gclient sync doesn't do anything

From Dev

Grunt Smoosher doesn't do anything

Related Related

HotTag

Archive