I'm trying to open a pdf by pressing a button on Ionic Capacitor using the FileOpener plugin, but it doesn't work, would anyone know how to help me?
The pdf is stored into assets/documents
In the console I get this error ".open, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator cordovaWarn @ common.js:284 ch".
This is my app.module.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 {}
And this is my page backend: 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));
}
}
And this the 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>
Thanks you
I want to show a pdf on the screen