[英]How to open pdf in ionic
How should I use ionic FileOpener? 我应该如何使用离子FileOpener? Or another way to show PDF file?
还是显示PDF文件的另一种方式? I have updated, but get error.
我已更新,但报错。
@Component({ selector: 'page-home', templateUrl: 'home.html' }) export class HomePage { page2 = Page2; ionViewDidLoad() { } pdfUrl : string; pins = PINS; str : string; constructor(public navCtrl: NavController, private fileOpener: FileOpener) { } onSelect(pin: Pin): void { this.fileOpener.open('assets/helloworld.pdf', 'application/pdf') .then(() => console.log('File is opened')) .catch(e => console.log('Error openening file', e)); } };
To open existing PDF file, you can use File Opener plugin. 要打开现有的PDF文件,可以使用File Opener插件。
First install the Cordova and Ionic Native plugins: 首先安装Cordova和Ionic Native插件:
$ ionic cordova plugin add cordova-plugin-file-opener2
$ npm install --save @ionic-native/file-opener
Then add this plugin to your app's module (app.module.ts): 然后将此插件添加到您应用的模块(app.module.ts):
...
import { FileOpener } from '@ionic-native/file-opener';
...
@NgModule({
...
providers: [
...
FileOpener
...
]
...
})
export class AppModule { }
Now you can use your plugin: 现在您可以使用插件了:
import { FileOpener } from '@ionic-native/file-opener';
constructor(private fileOpener: FileOpener) { }
...
this.fileOpener.open('path/to/file.pdf', 'application/pdf')
.then(() => console.log('File is opened'))
.catch(e => console.log('Error openening file', e));
Hope I help! 希望我能帮忙!
Below error comes in browser only. 以下错误仅在浏览器中出现。
Native: tried calling FileOpener.open, but Cordova is not available. Make
sure to include cordova.js or run in a device/simulator cordovaWarn @
util.js:60 Error openening file cordova_not_available.
you can make ionic app apk and install in device then check it is work. 您可以制作ionic app apk并安装在设备中,然后检查其是否正常运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.