Created
March 29, 2019 12:47
-
-
Save ovpv/027685439a605b5f7504a51eeea43ee1 to your computer and use it in GitHub Desktop.
home page ts file after calling pdf download and view service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { File } from "@ionic-native/file/ngx"; | |
import { | |
FileTransfer, | |
FileTransferObject | |
} from "@ionic-native/file-transfer/ngx"; | |
import { FileOpener } from "@ionic-native/file-opener/ngx"; | |
import { Injectable } from "@angular/core"; | |
@Injectable({ | |
providedIn: "root" | |
}) | |
export class PdfViewerService { | |
fileTransfer: FileTransferObject; | |
constructor( | |
private fileOpener: FileOpener, | |
private transfer: FileTransfer, | |
private file: File | |
) {} | |
download(url: string, title: string) { | |
this.fileTransfer = this.transfer.create(); | |
this.fileTransfer | |
.download(url, this.file.dataDirectory + title + ".pdf") | |
.then(entry => { | |
console.log("download complete: " + entry.toURL()); | |
this.fileOpener | |
.open(entry.toURL(), "application/pdf") | |
.then(() => console.log("File is opened")) | |
.catch(e => console.log("Error opening file", e)); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is wrong. According of your tutorial https://ovpv.me/open-pdf-ionic-4/ this is not the PdfViewerService, else home.page.ts:
https://github.com/ovpv/pdfviewer-ionic-4/blob/master/src/app/home/home.page.ts