I tried to work with ionic/cordova plugin here.
So I put this code in my Page:
showDocument() {
var options: DocumentViewerOptions = {
title: 'A book',
documentView: { closeLabel: '' },
navigationView: { closeLabel: '' },
email: { enabled: true },
print: { enabled: true },
openWith: { enabled: true },
bookmarks: { enabled: true },
search: { enabled: false },
autoClose: { onPause: false }
}
this.docViewer.viewDocument('assets/arabic.pdf', 'application/pdf', options);
}
And a simple button to launch it in the html page:
<ion-content>
<button ion-button round (click)="showDocument()">
Read
</button>
</ion-content>
But I can't see anything in the emulator (since it is not possible to run it on the browser)
Ionic Info is there:
UPDATE:
This is what I get when debugging with my device and chrome devtools:
UPDATE 2:
I have tried to work with absolute paths but I have got null value, I have made those changes:
import { File } from '@ionic-native/file';
declare let cordova: any;
//staff
pdfSrc: string = cordova.file.applicationDirectory + 'assets/arabic.pdf';
//staff
console.log(this.pdfSrc);
this.document.viewDocument(this.pdfSrc, 'application/pdf', options)
But see what I have got:
This does not answer your question directly, but is a workaround for getting PDFs to display.
I had trouble with a lot of plugins for reading PDFs, so I ended up just using a Mozilla project called PDF.js to render the PDF directly in the browser on the Android platform, and on iOS they are displayed natively in the browser. To handle it like a viewer, separately from the rest of my app, I used an in app browser window.
There are some code examples for PDF.js here: http://mozilla.github.io/pdf.js/examples/index.html#interactive-examples
Hope that helps someone!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With