laravel-snappy: Google charts not rendering in PDF
I could not figure out how to make Google Visualization Charts load in my pdf.
I tried with a high javascript-delay but still not working. Rendering the view works fine though.
Thanks
$pdf = \PDF::loadView('invoice', compact('data'));
$pdf->setOptions([
'enable-javascript' => true,
'javascript-delay' => 10000,
'images' => true,
'enable-smart-shrinking' => true,
'no-stop-slow-scripts' => true
]);
return $pdf->download('invoice.pdf');
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 22 (1 by maintainers)
Thank you! This worked!
For reference:
google.charts.load('current', {packages: ['corechart']}); var interval = setInterval(function() { if ( google.visualization !== undefined && google.visualization.DataTable !== undefined && google.visualization.PieChart !== undefined ){ clearInterval(interval); window.status = 'ready'; drawCharts(); } }, 100);
Encountered this issue recently. I have tried all the workarounds to fix the loading issue - setOnLoadCallback, delays, setInterval, setTimeout. Also tried upgrading the wkhtml version.
What worked for me is explicitly define the Google Charts version number to use. In my case version 44.
<script>google.load("visualization", "44", {packages:["corechart"]});</script>
Note: using version “1” now means you are using the current version. Per Google document - “All ‘jsapi’ requests are now being redirected to the new loader. If you were loading version ‘1’ or ‘1.0’, you will now be loading ‘current’.”
I had this same issue, tried @Abisco solution but it didn’t work too.
Update: Solved the issue by using wkhtmltopdf 0.12.5
Any current solution? I couldn’t make it work with version 0.12.6 of wkhtmltopdf. When I use window.status it just freezes and never finishes loading the pages.
@runerod, I’m generating the pdf from laravel view too. Here is the code I’m running in production (code extracted and adapted)
Hope it helps.
And again, it was broken. Thank you mate, you saved me. It begins to be really complicated to generate PDF with charts with laravel-snappy, honestly. I’m thinking about switching to a front end generator…
I resolved removing the “callback”:
Anyone having this problem, The Solution that I was using
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
stop working.The solution points by @Abisco Works great for me. Thanks
I found out it was related to this issue
I tried the old way to import google charts
Worked fine but not the latest version…
Please let me know you figured out a solution to load the latest version. Thanks