我试图通过使用FileOpener插件按下Ionic Capacitor上的按钮来打开PDF,但它不起作用,有人知道如何帮助我吗?
PDF存储到资产/文档中
在控制台中,我得到这个错误“.open,但Cordova不可用。确保包含cordova.js或在设备/模拟器cordovaWarn @ common.js:284 ch”中运行。
这是我的app. modul.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { File } from '@ionic-native/file/ngx';
import { FileOpener } from '@ionic-native/file-opener/ngx';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
providers: [
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
File,
FileOpener
],
bootstrap: [AppComponent],
})
export class AppModule {}
这是我的页面后端:open-pdf.page.ts:
import { Component, OnInit } from '@angular/core';
import { FileOpener } from '@ionic-native/file-opener/ngx';
import { File, IWriteOptions } from '@ionic-native/file/ngx';
@Component({
selector: 'app-open-pdf',
templateUrl: './open-pdf.page.html',
styleUrls: ['./open-pdf.page.scss'],
})
export class OpenPdfPage implements OnInit {
constructor(private fileOpener: FileOpener) { }
ngOnInit() {
}
openPdf(){
this.fileOpener.open('/assets/documents/mizzica.pdf', 'application/pdf')
.then(() => console.log('File is exported'))
.catch((e) => console.log(e));
}
}
这是HTML:
<ion-header [translucent]="true">
<ion-toolbar>
<ion-title>openPdf</ion-title>
</ion-toolbar>
</ion-header>
<ion-content [fullscreen]="true">
<ion-header collapse="condense">
<ion-toolbar>
<ion-title size="large">openPdf</ion-title>
</ion-toolbar>
</ion-header>
<ion-button (click)="openPdf()">Apri PDF</ion-button>
</ion-content>
谢谢你
我想在屏幕上显示一个pdf
1条答案
按热度按时间c9qzyr3d1#
我建议使用电容器文件打开器插件,例如。Capawesome File Opener或Capacitor Community File Opener。