繁体   English   中英

单击时,jspdf下载按钮不执行任何操作。 在Android Cordova中

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

我用cordova和angularjs制作了一个Android应用程序。 我已经下载了pdf按钮,并且可以在我的笔记本电脑上正常工作。 但是当编译成android时,我的按钮在点击时不会做任何事情。 我添加了插件cordova plugin add org.apache.cordova.file

我在这里按照教程http://www.tricedesigns.com/2014/01/08/generating-pdf-inside-of-phonegap-apps/和我的代码。

           $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 );
                    });
}

警报是有效的,但我的PDF文件仍无效。 有什么建议吗?

请执行下列操作

  1. 使用您的代码生成pdf并将其存储在本地,甚至更好地服务器端
  2. 安装应用内浏览器插件

     cordova plugin add cordova-plugin-inappbrowser 
  3. 创建一个下载按钮

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

这不仅将下载pdf,它将在浏览器/ pdf应用程序中打开pdf

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM