【问题标题】:Cordova jsPDF - PDF generated,I can not find the pdf file in MobileCordova jsPDF - PDF 生成,我在 Mobile 中找不到 pdf 文件
【发布时间】:2016-07-30 05:45:59
【问题描述】:

我在 cordova android 设备上运行, 我可以到达'console.log ("write success");'行但我不认为该文件没有出现在它的保存位置。

我试过在 2 个不同的机器人上运行, 创建一个pdf文件并保存在任何地方的任何文件夹中

源代码 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 );

谢谢!!

【问题讨论】:

  • 您找到解决方案了吗?我也面临同样的问题!
  • 不:{,我也需要帮助

标签: javascript android cordova cordova-plugins jspdf


【解决方案1】:

我的问题已解决

Opening a PDF in cordova javascript

jsPDF and cordova Cant view the pdf file

我试图将文件写入 root 并从那里访问它,这在非 root 手机中是不可能的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2020-11-18
    • 2018-12-06
    • 1970-01-01
    相关资源
    最近更新 更多