2016-05-24 6 views
0

私が抱えている問題を理解しようとしています。 私はAndroid用アプリケーションをCordovaからやっています。 解決策を探しましたが、実際には見つかりませんでした。Uncaught ReferenceError:LocalFileSystemが定義されていません

最初に私は定義されていない "requestFileSystem"に問題がありましたが、今修正されているようです。 問題を修正すると、問題は別の機能に移動しました。

私は基本的に作成する必要があり、ボタン、保存(そしておそらくショー)PDF持っている:機能を

function pdfCreation() { 

    //FIRST GENERATE THE PDF DOCUMENT ON TABLET, DOESN'T SHOW 
    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 pdfUriString = doc.output('datauristring'); 
    console.log(pdfUriString); 
    var pdfOutContainer = jQuery("#pdfOutContainer"); 
    pdfOutContainer.attr("src", pdfUriString); 

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

    document.addEventListener("deviceready", onDeviceReady, false); 
     function onDeviceReady() { 
      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); 
    }); 
} 

<!--Button to generate PDF--> 

     <div data-role="collapsible" data-inset="false" data-mini="true"> 
      <h3>Reports</h3> 

      <div> 
       <a href="javascript:pdfCreation()" class="button"data-role="button" id="PageUnitButtonGeneratePDIReport">Generate PDI Report</a> 
       <!--<iframe width="100%" height="500px" id="pdfOutContainer"></iframe>--> 
      </div> 

     </div> 

を、これは問題が含まれている私のJSコードであります問題はpdfCreationです。 jdfiddleをここに追加します。便利な場合もあります。

https://jsfiddle.net/antus2f0/

誰も私を助けることができれば、いいだろう! ありがとうございます。

答えて

1

コードを少し整理しました。それは}がありませんでした。また、jsFiddleで関数を実行している場合は、関数内に自動的にラップされるため、関数に対してis not definedエラーが発生します。

window.pdfCreation = function() { 

    //FIRST GENERATE THE PDF DOCUMENT ON TABLET, DOESN'T SHOW 
    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 pdfUriString = doc.output('datauristring'); 
    console.log(pdfUriString); 
    var pdfOutContainer = jQuery("#pdfOutContainer"); 
    pdfOutContainer.attr("src", pdfUriString); 

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

    document.addEventListener("deviceready", onDeviceReady, false); 

    function onDeviceReady() { 
    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); 
     }); 
    } 
} 
+0

ご回答いただきありがとうございます。 私が今持っているエラーは少し異なりますが、私はすでにいくつかのテストでそれを見つけました。 "Uncaught ReferenceError:LocalFileSystemが定義されていません" –

0

私は、うまくいけば、将来的に他の誰かを助けることができる次の作業ソリューションを得たコードの周りの作業:

はここで動作するコードです。

window.pdfCreation = function() { 

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

     doc.setFont("TimesNewRoman"); 
     doc.text(20, 10, 'HELLO!'); 
     doc.text(20, 30, 'This is a PDF summary.');  


     //PDF GENERATION ENDED 

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

     //NEXT SAVE IT TO THE DEVICE'S LOCAL FILE SYSTEM 
     console.log("file system..."); 
     alert("Creating PDF...Please wait a few seconds!"); 
     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) { 

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

      fileSystem.root.getFile($("#PageUnitPurchaserName").text() + $("#PageUnitUnitName").text() + ".pdf", {create: true}, function(entry) { 

       var fileEntry = entry; 
       console.log(entry); 

       entry.createWriter(function(writer) { 
        writer.onwrite = function(evt) { 
        console.log("write success"); 
        alert("PDF successfully created!"); 
       }; 

       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); 
     }); 
    } 
関連する問題