Chawki Tazzi
Chawki Tazzi

Reputation: 245

i can't open pdf file in ionic 3

I am working on a ionic 3 app and I want to open pdf file i putted in "assets/pdf" folder.

the probleme is win i click the button nothing happens

this is my code:

<ion-content padding>
<button ion-button (click)="openPdf()">open pdf </button>
</ion-content>

and this is typeScript:

openPdf(){
const options: DocumentViewerOptions = {
  title: 'My PDF'
}

this.document.viewDocument('assets/png2pdf.pdf', 'application/pdf', 
options)
}

i have tried many solutions nothing works

ps: i'm using an emulator

Please give me some suggestion

Upvotes: 0

Views: 445

Answers (1)

Chawki Tazzi
Chawki Tazzi

Reputation: 245

i found the solution

openPdf(){
let path = this.file.applicationDirectory + 'www/assets'

if(this.platForm.is('android')){
    let fackNama = Date.now();
    this.file.copyFile(path, 'omra_otla.pdf', this.file.dataDirectory, `${fackNama}.pdf`).then(result => {
      this.Fileopner.open(result.nativeURL, 'application/pdf')
    })
}else {
  const options: DocumentViewerOptions = {
    title: 'My PDF'
  }

  this.document.viewDocument(`${path}/omra_otla.pdf`, 'application/pdf', options)
}
}

Upvotes: 1

Related Questions