i make an android app with cordova and angularjs. I have made download pdf button and it works fine on my laptop. but when compiled to android, my button doesn't do anything when clicked. i have added plugin cordova plugin add org.apache.cordova.file
i followed tutorial here http://www.tricedesigns.com/2014/01/08/generating-pdf-inside-of-phonegap-apps/ and here my code.
$scope.exportPDF = function(){
alert("tes");
//FIRST GENERATE THE PDF DOCUMENT
console.log("generating pdf...");
var doc = new jsPDF();
doc.text(20, 20, 'HELLO!');
doc.setFont("courier");
doc.setFontType("normal");
doc.text(20, 30, 'This is a PDF document generated using JSPDF.');
doc.text(20, 50, 'YES, Inside of PhoneGap!');
var pdfOutput = doc.output();
console.log( pdfOutput );
//NEXT SAVE IT TO THE DEVICE'S LOCAL FILE SYSTEM
console.log("file system...");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
console.log(fileSystem.name);
console.log(fileSystem.root.name);
console.log(fileSystem.root.fullPath);
fileSystem.root.getFile("test.pdf", {create: true}, function(entry) {
var fileEntry = entry;
console.log(entry);
entry.createWriter(function(writer) {
writer.onwrite = function(evt) {
console.log("write success");
};
console.log("writing to file");
writer.write( pdfOutput );
}, function(error) {
console.log(error);
});
}, function(error){
console.log(error);
});
},
function(event){
console.log( evt.target.error.code );
});
}
the alert is worked, but my pdf still not work. any suggestion?
Do the following
Install In-App browser plugin
cordova plugin add cordova-plugin-inappbrowser
Create a download button with
onclick="window.open("LOCAL_OR_REMOTE_URL", '_system');
Not only will this download the pdf it will open the pdf in the browser/pdf app
<button class="btn btn-default" onclick="window.open(PDF_URL, '_system')">
<i class="fa fa-file-pdf-o"></i> PDF
</button>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments