Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

jsPDF not working on device

I am trying use jsPDF to generate a pdf file. I have created a test page which just runs javascript on load. It outputs the pdf to screen and then saves it to disk. This works using the test button in the dev environment, but does nothing apart from show an empty page on my device.

The Device is a Hudl 2 Android version 5.1 and it has adobe reader installed.

Any ideas how I can debug, or why it may not work?

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

jsPDF not working on device

Just checked, viewing on chrome browser on device and it works ok, just not as an apk

Maybe what I need to do is execute the code in an In App Browser?

If so is it possible to execute javascript in an In App Browser from the calling app?

The problem with this idea is that i would probable have to write all the javascript code to the child window, including the jsPDF library!, before executing the function.

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

jsPDF not working on device

Terry,

It's hard to say now what is the reason of such behaviour as you are using 3rd party JS code, but we'll try to help. Could you please provide us with the code that you are using and also please specify have you changed any Android permissions and have you tested your app with the Appery.io tester?

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

jsPDF not working on device

I think that the best thing to do is share the app with you.

The app is called MyInvoiceBuddy. If you log on as username 'terry', password 'ravine', click Invoices off the menu and then click View PDF of Invoice, you will see a sample invoice come up in the testing browser.

It will not work as an apk or through the android testing app. If you view it on the browser of the device, it also works ok.

I have turned on share with support.

The jsPDF library is stored as jsPDF and it has an extension to the text function called textEX which allows text alignment. This is added to the end of the jsPDF file.

to the best of knowledge, I have not changed any permissions.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

jsPDF not working on device

Hello Terry,

Please check if there are any errors in the Weinre console. You can learn here: https://devcenter.appery.io/documenta... how to open the console.

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

jsPDF not working on device

Ok, I have tried weinre debugging and there are no errors in the console.

I added some console.log statements in the pdf script and it seems to execute them perfectly, just not showing up on the display.

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

jsPDF not working on device

just a little nudge, system doesn't seem to realise that I have replied

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

jsPDF not working on device

Unfortunately this is outside the scope of our support. Please search online for appropriate solution.

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

jsPDF not working on device

I don't believe that there will be on on-line solution to something that is only related to an appery app

Terry Gilliver
Posts: 0
Joined: Fri Apr 18, 2014 8:45 pm

jsPDF not working on device

I found a sample cordova/jsPDF app on Github containing the following js:

prevar JutoPDFCreator = {
createPDF: function(filename) {
var doc = new jsPDF();
doc.text(20, 20, 'Hello world!');
doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
doc.addPage();
doc.text(20, 20, 'From within Cordova.');
var uristring = doc.output('datauristring');

Code: Select all

 // the email plugin uses a non-standard URI format, so the filename can be specified. 
 if (filename) { 
   var uristringparts = uristring.split(','); 
   uristringparts[0] = "base64:" + escape(filename) + "//"; 

   var moddeduristring =  uristringparts.join(""); 
   return moddeduristring; 
 } else { 
   return uristring; 
 } 

},
displayPDF: function(uristring) {
var ref = window.open(uristring, "_blank", "EnableViewPortScale=yes,location=no,disallowoverscroll=yes,allowInlineMediaPlayback=yes,toolbarposition=top,transitionstyle=fliphorizontal");
return ref;
},
createAndDisplayPDF: function(filename) {
var uristring = this.createPDF(filename);
var ref = this.displayPDF(uristring);
return ref;
},
emailPDF: function(datauri) {
if (!window.plugin || !window.plugin.email) {
console.error("no cordova-plugin-email-composer available");
return;
}

Code: Select all

 var emailProperties = { 
   to: ["mikecunneen@example.com"], // email addresses for TO field 

// cc: [], // email addresses for CC field
// bcc: [], // email addresses for BCC field
attachments: [datauri], // paths to the files you want to attach or base64 encoded data streams
subject: "Sample PDF", // subject of the email
body: "Sample PDF is attached.
", // email body (could be HTML code, in this case set isHtml to true)
isHtml: true // indicats if the body is HTML or plain text
};
var emailCallback = function() {
console.log('email view dismissed');
};
window.plugin.email.isServiceAvailable(
function(isAvailable) {
window.plugin.email.open(emailProperties, emailCallback, this);
}
);
},
createAndEmailPDF: function(filename) {
var uristring = this.createPDF(filename);
this.emailPDF(uristring);
}
};/pre

I renamed the object to InvoicePDFCreator and called codeInvoicePDFCreator.createAndDisplayPDF();/code via a button click event.
This code actually opens a new window to display the PDF, which kinda makes sense.

Again, though, it works in the browser, but not in the apperyio tester app. It opens the new window, but it is blank, again no errors in weinre debugging

Return to “Issues”