I´m having issues trying to open a PDF file blob generated with jspdf using cordova. I found that there is a lot of 'security' measures on Android that make incredibly difficult to open from a saved file, more for me because I´m noob with cross platforms apps, so I need to find a way to open the blob without saving.
I tried but the console shows me: "Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided."
This is my function to generate the pdf blob:
function createPDF(){
console.log("generating pdf...");
var doc = new jsPDF();
doc.text(20, 20, 'Document title');
doc.setFont("courier");
doc.setFontType("normal");
doc.text(20, 30, 'test first line');
doc.text(20, 50, 'test second line');
var blobPDF = doc.output();
var blobUrl = URL.createObjectURL(blobPDF); <--- THE ERROR APPEARS HERE
window.open(blobUrl,'_system','location=yes');
}
What I need is open the file so Android gives me the optional apps to open (Adobe reader, etc).
How can I make this code work for Android? I tried a lot of examples but always there's some kind of problem.
Just in case I'm using Intel XDK (ver 3522) and I included the File, File-Transfer, InAppBrowser, FileOpener2 plugins.
Try this, works for me :
var blobPDF = new Blob([ doc.output() ], { type : 'application/pdf'});
var blobUrl = URL.createObjectURL(blobPDF); //<--- THE ERROR APPEARS HERE
window.open(blobUrl); // will open a new tab
//window.open(blobUrl,'_system','location=yes'); will open a new window
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