Skip to content

Instantly share code, notes, and snippets.

@ovpv

ovpv/home.page.ts

Created Mar 29, 2019
Embed
What would you like to do?
home page ts file after calling pdf download and view service
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));
});
}
}
@miguelcarrascoq

This comment has been minimized.

Copy link

@miguelcarrascoq miguelcarrascoq commented Dec 12, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment