Hi,
I am using PDFMake in my assignment, its working as expected (on android device and on laptop) and like to thank you for this.
However, Download() method not working on android devices.
My requirement is, after I show the PDF, pdfMake.createPdf(documentDefination).open(), I want to download same pdf to my android device and for this I am using pdfMake.createPdf(documentDefination).downlaod("test.pdf"). Its working fine on chrome but not on physical android device.
Does it save the PDF some other location on device or how I can achieve this?
Girish D. Fuluskar
Hi Guys, any updates on this, can we expect a fix here soon for android and ios?
Any updates?
any updates on this? I am also facing same issue. where does file gets saved on the device after calling download and how to get the complete path?
any news on this, downloading is not working on android devices, and also opening, opens a new blank tab
I found a workaround, and it's working seamlessly both on android and ios.
const doc = pdfMake.createPdf(docDefinition);
doc.getBase64((data) => {
window.location.href = 'data:application/pdf;base64,' + data;
});
Hope this helps
@marcomessa You helped me a lot! Tks!
You are welcome!
Be aware that this solution is gonna be deprecated in future Chrome versions!
But for now is a nice workaround!
@marcomessa Followd the steps you have specified.But showing this in the console.
Resource interpreted as Document but transferred with MIME type application/pdf
Also No new window is opening in chrome.Can u suggest any solutions
Any update on this?
For some reason marcomessa workaround is not working neithe ron chrome neither on mobile device.
Chrome on Android throws error after download pdf file - "download failed due to unknown error":
=> In actual Chrome versions works download() correctly in Android 6 and 7.
// edited issue title
someone find a solution? I'm building a cordova app and .download() don't work on devices.
Below code(Ionic) is works for me, tested on Android/iOS/Browsers.
[NOTE: I'm using [file opener plugin](https://github.com/pwlin/cordova-plugin-file-opener2) to open PDF.]
if (this.platform.is('cordova')) {
// FOR MOBILE DEVICES
pdfmake.createPdf(newdd).getBuffer((buffer) => {
var utf8 = new Uint8Array(buffer); // Convert to UTF-8...
let binaryArray = utf8.buffer; // Convert to Binary...
let dirPath = "";
if (this.platform.is('android')) {
dirPath = this.file.externalRootDirectory;
} else if (this.platform.is('ios')) {
dirPath = this.file.documentsDirectory;
}
let dirName = 'DailySheet';
this.file.createDir(dirPath, dirName, true).then((dirEntry) => {
let saveDir = dirPath + '/' + dirName + '/';
this.file.createFile(saveDir, fileName, true).then((fileEntry) => {
fileEntry.createWriter((fileWriter) => {
fileWriter.onwriteend = () => {
this.hideLoading();
this.showReportAlert('Report downloaded', saveDir + fileName);
this.fileOpener.open(saveDir + fileName, 'application/pdf')
.then(() => console.log('File is opened'))
.catch(e => console.log('Error openening file', e));
};
fileWriter.onerror = (e) => {
this.hideLoading();
this.showAlert('Cannot write report', e.toString());
};
fileWriter.write(binaryArray);
});
}).catch((error) => { this.hideLoading(); this.showAlert('Cannot create file', error); });
}).catch((error) => { this.hideLoading(); this.showAlert('Cannot create folder', error); });
}).catch((error) => { this.hideLoading(); this.showAlert('Error while creating pdf', error); });
}
else {
//FOR BROWSERS
pdfmake.createPdf(newdd).download(fileName);
this.hideLoading();
}
@niravparsana94 You helped me a lot! Thanks
@niravparsana94 You helped me a lot! Thanks
I'm glad. :)
Android not support open pdf in browser, but open invokes dialog to open document.
Most helpful comment
I found a workaround, and it's working seamlessly both on android and ios.
const doc = pdfMake.createPdf(docDefinition); doc.getBase64((data) => { window.location.href = 'data:application/pdf;base64,' + data; });Hope this helps