jsreport / jsreport-phantom-pdf

jsreport recipe which is rendering pdf from html using phantomjs
GNU Lesser General Public License v3.0
11 stars 8 forks source link

images not proper loading in a long report #19

Closed BillMa1992 closed 7 years ago

BillMa1992 commented 7 years ago

I met a problem when I'm doing a report where each page has a map image.

I have another jsreport-image template to generate map images using url requests. And then I directly insert the image results into the report.

  1. It can only properly print the first 12 pages with map images.
  2. After setting "phantom": {"strategy": "phantom-server"}, it can properly print first 24 pages.
  3. I think that's a problem about enabling disk-cashe and setting its size. However, I don't know where I can set that in jsreport. Does anyone know the place? Thank you!

Best, Bill

bjrmatos commented 7 years ago

hmm maybe your problem is related to the fact that your map images requests are async and phantomjs is not waiting until all images are loaded to start the printing.

have you tried to activate a printing trigger?

you have the option to activate the waitForJS option and then you just need to set the JSREPORT_READY_TO_START = true variable in the javascript part (<script> part) of your template, this will let you control exactly when phantomjs should start printing the page.

for example after activating the waitForJS property of your template (a checkbox in jsreport studio) try to put a javascript like this in your template:

// ...html here...
<script>
    // put a fake time, just to see if that your problem is indeed a race condition 
    // between phantomjs and your map images
    setTimeout(function() {
        window.JSREPORT_READY_TO_START = true; //this will start the pdf printing
    }, 5000);
    ...
</script>
bjrmatos commented 7 years ago

an example to give you and idea: https://playground.jsreport.net/studio/workspace/rkYn7WaCg/19

BillMa1992 commented 7 years ago

Thanks for your quick response. Yes, it's seems to be the problem. By setting "window.JSREPORT_READY_TO_START = true;" now I get more map successfully printed. However, there are still 2 maps that fail to print.

A lot of warnings like this: image

and the error canceling the print looks like this: image

bjrmatos commented 7 years ago

it is something difficult to tell you what is happening (or if there is any kind of issue) without looking what you have in the template, the first warning seems like an error in the javascript part of your template

can you share here the content of your template (template, helpers etc)?

BillMa1992 commented 7 years ago

Thanks for your reply. I think the issue can be closed. Since it's something with Phantom.js. I may not use the async strategy to do the printing tasks. Again, thank you for your fast reply!

Best, Bill