2017-06-03 69 views
0

我能够在离子应用程序中创建pdf,如果我在Chrome中运行应用程序,它将完美打开。但是,如果我在Android设备上安装我的应用程序,它不会打开。以下是我的代码。如果我必须做额外的事情才能在设备上打开它,有人可以帮助我吗?我想用设备上的默认PDF应用程序打开它。在默认应用程序中使用pdf打开pdfmake

pdfMake.createPdf(dd).open(); 

回答

2

好的。在将我的头撞在墙上3天后,我终于找到了解决方案并在此分享,以便其他面临此问题的人员可以获得帮助。我正在创建pdf并使用cordova文件插件进行保存。成功保存后,我使用cordova file opener插件在默认应用程序中打开它。以下是我的代码。

pdfMake.createPdf(YOUR_DEFINITION_HERE).getBlob(buffer => { 
    this.file.resolveDirectoryUrl(this.file.externalRootDirectory) 
    .then(dirEntry => { 
     this.file.getFile(dirEntry, 'test1.pdf', { create: true }) 
     .then(fileEntry => { 
      fileEntry.createWriter(writer => { 
      writer.onwrite =() => { 
       this.fileOpener.open(fileEntry.toURL(), 'application/pdf') 
       .then(res => { }) 
       .catch(err => { 
        const alert = this.alertCtrl.create({ message: 
err.message, buttons: ['Ok'] }); 
        alert.present(); 
       }); 
      } 
      writer.write(buffer); 
      }) 
     }) 
     .catch(err => { 
      const alert = this.alertCtrl.create({ message: err, buttons: ['Ok'] }); 
      alert.present(); 
     }); 
    }) 
    .catch(err => { 
     const alert = this.alertCtrl.create({ message: err, buttons: ['Ok'] 
}); 
     alert.present(); 
    }); 
}); 
+0

感谢you.With答案我能在我的ionic2 app.But创建PDF是有可能没有我的应用程序创建file.Because显示PDF我有一个选项来预览PDF所以我不需要保存文件。我尝试通过修改您的代码按照我的要求,像创建和打开文件后,我试图删除文件,但我不能成功,因为它是抛出错误,告诉文件不存在。可以让你请建议我在离线2应用程序中查看PDF而不保存它的方法 –

+0

@abhilashreddy我不确定这是否可能,但我会尽力让你知道。 – Prabi

+0

谢谢先生... –

相关问题