【问题标题】:document-viewer in ionic not working not open file离子中的文档查看器不工作未打开文件
【发布时间】:2018-12-18 13:22:49
【问题描述】:

您好,我使用以下代码不起作用如何解决它..

 fileTransfer.download(url, path + 'abcd.pdf').then((entry) => {
            let localUrl = entry.toURL();
            const toast = this.toast.create({
              message: 'Download Complted',
              duration: 20000,
              position: 'top',
              closeButtonText: 'OK',
              showCloseButton: true,
            });
            toast.present();
            this.document.viewDocument(localUrl, 'application/pdf', {});
        }, (error) => {
            // handle error
            console.log("In error");
            console.log(error);
            alert(JSON.stringify(error));
        });

它是如何工作的!!

【问题讨论】:

  • 您面临什么样的问题?请添加一些与您在使用上述代码时遇到的问题相关的详细信息。
  • 问题就像文件已下载但无法在 documentViewer 中打开。我的意思是 this.document.viewDocument(localUrl, 'application/pdf', {});这--> 行不工作

标签: ionic-framework ionic3 documentviewer


【解决方案1】:

您是否在项目中添加了文档查看器插件?请看这个链接https://ionicframework.com/docs/native/document-viewer/你可以找到命令。

ionic cordova plugin add cordova-plugin-document-viewer
npm install --save @ionic-native/document-viewer

那么您还必须在 viewDocument 函数中传递选项

      fileTransfer.download(url, path + 'abcd.pdf').then((entry) => {
            let localUrl = entry.toURL();
            const toast = this.toast.create({
              message: 'Download Complted',
              duration: 20000,
              position: 'top',
              closeButtonText: 'OK',
              showCloseButton: true,
            });
            toast.present();
             const options: DocumentViewerOptions = {
             title: 'My PDF'
            }
            this.document.viewDocument(localUrl, 'application/pdf', options);
        }, (error) => {
            // handle error
            console.log("In error");
            console.log(error);
            alert(JSON.stringify(error));
        });

希望这对你有用!

【讨论】:

  • 我做了和上面一样但是文件没有打开
猜你喜欢
  • 2018-07-10
  • 1970-01-01
  • 1970-01-01
  • 2013-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-22
  • 2019-03-04
相关资源
最近更新 更多