2016-03-21 14 views
1

私はコードアンドアングルでアンドロイドアプリを作っています。私はpdfボタンをダウンロードして、それは私のラップトップ上で正常に動作します。しかし、アンドロイドにコンパイルすると、私のボタンはクリックされても何もしません。私はプラグインを追加しましたcordova plugin add org.apache.cordova.filejspdfダウンロードボタンはクリックしても何もしません。 android cordovaで

私はここでチュートリアルに従います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はまだ機能しません。なにか提案を?

答えて

0

作成アプリ内ブラウザプラグインPDFファイルを生成し、それをローカルに保存したり、より良いそれをサーバ側

  • インストールを行うには

    cordova plugin add cordova-plugin-inappbrowser 
    
  • をあなたのコードを使用して、次

    1. を実行します。ダウンロードボタン付き

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

    だけでなく、このPDFの私のPDFファイルを生成するために、それはNGクリックボタンクラス= "BTN BTN-デフォルト" < `ブラウザ/ PDFアプリ

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

    にこのボタンをPDFファイルが開きますをダウンロードします=」あなたはサンプルコードを与えることができますか?あなたのコードのように 'onclick'をどこに置くべきですか? –

    +0

    更新を参照してください...... – aWebDeveloper

    +0

    私はPDFをexportPDF関数で生成できません。私は何が問題なのか分からない。だからあなたのコードでPDF_URLについて知りません。なぜなら私は自分のpdfをローカルに生成できないからです。 –

    関連する問題