Somnath
Somnath

Reputation: 406

How to open pdf file into a div or a tab using ionic 3?

How to open pdf file into a div or a tab using ionic 3 ? Using below code I can open pdf by pdf reader outside from app. I want to show it into a div. Please give me some suggestion.

import { DocumentViewer } from '@ionic-native/document-viewer';


constructor(private document: DocumentViewer) { }

...
const options: DocumentViewerOptions = {
  title: 'My PDF'
}

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

Upvotes: 1

Views: 3840

Answers (1)

Christian Benseler
Christian Benseler

Reputation: 8065

You can use a pdf viewer component for Angular 2+ application. You can write your own or use some available at npm. Example: https://github.com/VadimDez/ng2-pdf-viewer

Template:

<ion-content>
 <pdf-viewer
  [src]="pdfSrc" 
  [render-text]="true"
  style="display: block;"
 ></pdf-viewer>
</ion-content>

component.ts

pdfSrc: string = '/pdf-test.pdf';

Upvotes: 1

Related Questions