pdf-generator icon indicating copy to clipboard operation
pdf-generator copied to clipboard

Android create one page per assets (image) in PDF

Open Chousse opened this issue 6 years ago • 7 comments

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,

Chousse avatar Jan 02 '19 14:01 Chousse

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!.

cesarvr avatar Jan 02 '19 14:01 cesarvr

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 avatar Jan 03 '19 12:01 Chousse

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

Chousse avatar Jan 04 '19 11:01 Chousse

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.

  • Try to render the content in the server-side.
  • Use onReady events.

cesarvr avatar Jan 04 '19 13:01 cesarvr

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 avatar Jan 04 '19 14:01 Chousse

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 avatar Jan 08 '19 10:01 Chousse

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

Chousse avatar Jan 14 '19 09:01 Chousse