2017-06-03 67 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

謝謝先生... –

相關問題