gpt4 book ai didi

typescript - 如何使用 ionic 4 在网络浏览器中打开 pdf?

转载 作者:行者123 更新时间:2023-12-05 06:25:02 25 4
gpt4 key购买 nike

我正在创建 ionic 4 角度应用程序,并使用文件、文件打开器、文件传输、文档查看器在移动设备中打开 pdf。现在我想在网络浏览器中打开 pdf?在我打开 pdf 的代码下面......

 // My method for open pdf

openLocalPdf() {
let filePath = this.file.applicationDirectory + 'www/assets';

if (this.platform.is('android')) {
let fakeName = Date.now();
this.file.copyFile(filePath, '5-tools.pdf', this.file.dataDirectory, `${fakeName}.pdf`).then(result => {
this.fileOpener.open(result.nativeURL, 'application/pdf')
.then(() => console.log('File is opened'))
.catch(e => console.log('Error opening file', e));
})
} else {
// Use Document viewer for iOS for a better UI
const options: DocumentViewerOptions = {
title: 'My PDF'
}
this.document.viewDocument(`${filePath}/5-tools.pdf`,
'application/pdf', options);
}
}

最佳答案

一种选择是使用 IAB/InAppBrowser为此。

您可以使用这行代码:

this.iab.create("https://www.example.com/some.pdf", '_system', 'location=yes');

它旨在让您在设备上打开系统浏览器和其他东西,但在桌面上它只会在浏览器的新选项卡中打开链接。

我假设您可以查找 platform 代码来检测需要绕过它的桌面平台。

关于typescript - 如何使用 ionic 4 在网络浏览器中打开 pdf?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57320771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com