Hello guys, i want to use jsPDF library with IONIC3 to download PDF , i have created a simple document and when i try to download it with the default function from jsPDF doc.Save()
it work in my browser , but in a real device won’t work.
So i decided to use FileTransfer Plugins from IONIC native , i have firstly created a blob File from jsPDF output , then i tried to use the writeFile()
function from IONIC FILE plugin to create a new file from the blob , then i tried to download that file using Download()
function from FileTransfer , Here is my code :
`
createPdf(){
const fileTransfer: FileTransferObject = this.transfer.create();
//Initialize jsPdf
let doc = new jsPDF();
doc.setFontStyle('Bold');
doc.setFontSize(14);
doc.text('Testing PDFs', 20, 20);
// doc.save("example.pdf") This is the default way to download pdf In jsPDF , but it's not working in ionic
// So Here i create new File from the blob
let blob = doc.output('blob', {type: 'application/pdf'});
this.file.writeFile(this.file.dataDirectory,"example.pdf",blob)
.then((value)=>{
console.log("File created successfly" + value);
// if The file successfuly created , i want to download it
fileTransfer.download( this.file.dataDirectory+"example.pdf" ,this.file.dataDirectory+"example.pdf")
.then((entry)=>{
console.log("Download Success : " , entry);
})
.catch((error)=>{
console.log("Error when downloading file : " ,error);
})
})
.catch((error)=>{
console.log("Error creating File");
});
)
`
if i look to my output console everything work ok , but nothing Happen !!
[19:50:26] console.log: File created successfly{“isFile”:true,“isDirectory”:false,“name”:“example.pdf”,“fullPath”:“/example.pdf”,“filesystem”:“<FileSystem:
files>”,“nativeURL”:"file:///data/user/0/io.ionic.starter/files/exam[19:50:26] console.log: Download Success :
{“isFile”:true,“isDirectory”:false,“name”:“example.pdf”,“fullPath”:“/example.pdf”,“filesystem”:“<FileSystem:
files>”,“nativeURL”:“file:///data/user/0/io.ionic.starter/files/example.pdf”}