cesarvr / pdf-generator

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

Android create one page per assets (image) in PDF #91

Open Chousse opened 5 years ago

Chousse commented 5 years ago

Hi everyone, I'm using phonegap to export in ios/android.

I've an issue on android, when I generate the pdf, I have a multipage pages PDF with one asset per page and the html is like not rendered.

With the same code on ios it works, but I have a problem of scale, maybe the retina ?

Anyone have an idea ?

Thanks a lot, regards,

cesarvr commented 5 years ago

Hi, can you share a quick example of the code you are using for this ?

Also you can copy the code from this example which includes an example very similar to what you try to achieve.

Cheers!.

Chousse commented 5 years ago

thanks, var tmpHTML = '<!DOCTYPE html><html lang="'+app.options.lang+'">'; tmpHTML += '<head><meta charset="utf-8">'; tmpHTML += '<link rel="stylesheet" href="<%=css_file%>">'; tmpHTML += '</head><body>'; tmpHTML += "<div id='templateScene'><div id='templateScene-content'>"; tmpHTML += $("#temp-pdf-generate").html(); tmpHTML += "</div></div>"; tmpHTML += "</body></html>"; var opts = { fileName:filename, type:'share', documentSize: 'A4', landscape:'landscape', } cssFile = dirAssets+"/assets/css/print.css"; var payload = _.template(tmpHTML); pdf.fromData(payload({css_file: cssFile}), opts) .then(progressHide) .catch(progressHide);

Chousse commented 5 years ago

Re, I fix the problem in ios. PDF is fine. But on android, same problem. I have 13 pages with an assets per page ! I don't understand why ! I follow the example (because it work properly on ios) can you please help me ? thanks

cesarvr commented 5 years ago

Are you able to run the example successfully ?

Check if the content right.

Are you getting any errors or just a white page?

Can you try to render _.template(tmpHTML) in the browser (on Android) and see if you see something? Example:

document.getElementsByTagName('HTML')[0].innerHTML= _.template(tmpHTML)

Async Problems

Also keep in mind if the content of #temp-pdf-generate is loaded asynchronously , you need to take proper measures to make sure the content is loaded, before executing the transformation to PDF.

Chousse commented 5 years ago

the render is ok because $elem.html() just getting front HTML and put it into template() to render a PDF. as I said on IOS same code work perfectly.

I have no errors and no blank page, juste all images and text content in each page of a "18 pages PDF" !

I'm not able to render in serverside cause it's an offline app. I'm not using onReady event but I've put a 2sec timeout before calling pdf.fromData() (as I said work fine on IOS platform)

Chousse commented 5 years ago

Hi, When I wrote your example : document.getElementsByTagName('HTML')[0].innerHTML= _.template(tmpHTML) rendered me in plaintext in browser : function(n){return o.call(this,n,m)}

Chousse commented 5 years ago

Hi, I can't find why this happened, have you got an idea? Thanks