cesarvr / pdf-generator

Cordova plugin to generate pdf in the client-side
MIT License
107 stars 61 forks source link

Not Generating PDF #58

Closed BrianMoreno1994 closed 6 years ago

BrianMoreno1994 commented 6 years ago

Hi, I'm currently trying to generate a PDF from my Android device. Unfortunately, when I try to generate it nothing happens. This is the code I'm using:

let options = {
      documentSize: 'A4',
      type: 'share'
}

pdf.usingURL('http://192.168.1.171/table.php', options).then(() => alert('ok')).catch((err) => alert(err))

Any help will be greatly appreciated! :)

These are my cordova plugins installed:

cordova-pdf-generator 1.9.3 "PDFGenerator"
cordova-plugin-whitelist 1.3.3 "Whitelist"

Android Version: Android Version 7.0

cesarvr commented 6 years ago

Hi, are you getting any error message ?, you can look for the error message by using chrome remote debugger in your phone.

BrianMoreno1994 commented 6 years ago

Thank for your reply. When using the remote debugger I get the following message in the console:

vendor.js:1 TypeError: pdf.usingURL is not a function
    at a. table (5.e6c91e714285ec609d3f.js:1)
    at a.n [as table] (vendor.js:1)
    at click (5.e6c91e714285ec609d3f.js:1)
    at a.e (vendor.js:1)
    at a.t.$emit (vendor.js:6)
    at a.click (vendor.js:11)
    at n (vendor.js:1)
    at e (vendor.js:1)
    at HTMLButtonElement.t._withTask.t._withTask (vendor.js:1)
cesarvr commented 6 years ago

Sorry about that, I made a mistake in the documentation the real method is fromURL and fromData, I have updated the documentation with the correct methods. Thank you! very much for reporting it. 👍

BrianMoreno1994 commented 6 years ago

Perfect, but unfortunately it now gets stuck on the "Preparing preview..." screen.

This is what I'm trying:

let options = {
      documentSize: 'A4',
      type: 'share'
}

pdf.fromData('<html><h1>Hello World</h1></html>', options).then(() => alert('ok')).catch((err) => alert(err))

I also tried fromURL and it also gets stuck on that same screen.

cesarvr commented 6 years ago

I found the problem, is in the alert, it will popup and focus the current WebKit, so basically the next view will wait until you click the alert, but the problem is you won't be able to go back. long history short if you want to get feedback choose console.log, DOM Modal like SweetAlert2 or you can use a native Progress Bar.

This would work:

 pdf.fromData('<html><h1>Hello World</h1></html>', options)
            .then(() => console.log('ok'))
            .catch((err) => alert(err))
BrianMoreno1994 commented 6 years ago

Ahh I see, thanks a lot for your help, it's working now. This is really an excellent plugin. I'm gonna for sure share your work! 👍

Thanks again!