cesarvr / pdf-generator

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

Plain HTML to PDF not working on iOS #93

Closed frankego closed 5 years ago

frankego commented 5 years ago

When I use the function that accepts the URL, it works without problems. But when i use htmlToPdf or fromData the promise status is ever in "Pending". With the previous version of the plugin it worked without problems. I tried to debug but I do not get any errors, it simply stays pending.

Do you have any suggestions or can you indicate on some piece of code to investigate? Many thanks!

cesarvr commented 5 years ago

Hi, is this happening in a platform in particular iOS, Android or both ?

frankego commented 5 years ago

Hi cesar, only on iOS. In androids works well. I've the latest version of Cordova and plugin.

cesarvr commented 5 years ago

Hi @frankego I think I found the problem, I just pushed the fix for version 2.0.8.

cordova plugin remove cordova-pdf-generator
cordova plugin add cordova-pdf-generator@2.0.8

I think this should solve the problem.

frankego commented 5 years ago

It works!! Thank you for your time and for fast bugfix!!

sathishavunoori commented 4 years ago

Hi @cesarvr i have also faced the same issue as like @frankego faced and i have installed 2.0.8 and 2.1.1, now the pdf is generated but without any content on it. it is showing empty pdf files. I have added screenshot of the PDF file. My case is to create a PDF and send to print. I have used cordova-plugin-printer but it is generating PDF with some CSS alignment issues. can you please let me know what needs to be done for my issue. I am calling the API like below "pdf.fromData( document.getElementsByTagName('html')[0].innerHTML, { documentSize: 'A4', type: 'share', fileName: 'myFile.pdf' }) .then((stats)=> console.log('status', stats) ) // ok..., ok if it was able to handle the file to the OS.
.catch((err)=>console.log(err))"

Screenshot 2020-06-03 at 4 38 25 PM
cesarvr commented 4 years ago

You need to make sure that the content of document.getElementsByTagName('html')[0].innerHTML is not empty.

pdf.fromData( 
document.getElementsByTagName('html')[0].innerHTML,  
{ documentSize: 'A4', 
   type: 'share',
   fileName: 'myFile.pdf'
})
.then((stats)=> console.log('status', stats) ) // ok..., ok if it was able to handle the file to the OS.
.catch((err)=>console.log(err))

Also to debug that the plugin is working currently you can try adding some simple HTML like <h1>Hello World</h1> as payload for example:

Also you can use this example.