Chart to wkhtmltopdf not working
andrewskm opened this issue · 4 comments
What Version?
3.1.12
Issue
I am trying to display charts on a PDF using laravel-snappy (which uses wkhtmltopdf). This transforms the views easily into pdfs, so testing the html version, charts work fine.
I know the pdf needs time for the javascript to run, so I've applied the auto_run config to false so that I can run the window.lava.run()
in a function when the body onloads.
A test to make sure the chart drawing feature is working is taking an example from Google Charts and placing in this function, which it does perfectly.
Below is some of my view code and wkhtmltopdf options.
Is there something I am missing?
View Code
<script src="https://www.gstatic.com/charts/loader.js"></script>
{!! Lava::lavajs() !!}
<script type="text/javascript">
function init()
{
var interval = setInterval(function()
{
try
{
window.google.charts.load('46', {packages: ['corechart']});
if(google.visualization !== undefined)
{
window.status = 'ready';
clearInterval(interval);
window.lava.run();
}
}catch(e)
{
$('#display-error').html('Error parsing javascript: ' + e.message);
clearInterval(interval);
}
}, 500);
}
</script>
</head>
<body onload="init();">
...
<div id="chart-contain"></div>
...
{!! Lava::renderAll() !!}
</body>
wkhtmltopdf Options
'enable-javascript' => true,
'javascript-delay' => 3000,
'no-stop-slow-scripts' => true,
'load-error-handling' => 'ignore',
'enable-smart-shrinking' => true,
upon first glance... you don't need to include
<script src="https://www.gstatic.com/charts/loader.js"></script>
or
window.google.charts.load('46', {packages: ['corechart']});
as the library was designed to handle all that
Side question...
What do you think about this?
I thought the library brought in the loader.js as well, but for some reason the charts do not load without it (this may be caused by the auto_run config being set to false).
The google package load is only set as a temp fix for this issue #326.
The LavaJs looks good, making it it's own library outside of lavacharts will allow it to be used on a broader spectrum where the framework may not be Laravel. Nice work!