Print ChartWidget in PDF (DomPDF)

Hey guys, I'm creating a project and I need to print a PDF that would be an Academy training sheet, and I would like to place a line graph on the training sheet that I created as a WidgetChart, this graph is already working in two places in my application. To print this PDF, I created a blade template and I'm printing it with DOMPdf, but when I put it in the PDF, only the title of the graph appears and nothing else.
No description
No description
7 Replies
Matthew
Matthew2w ago
Hmm, I think the best way to do it ( although I've never tried it), is to create a chart widget, and then inject it to your blade template https://filamentphp.com/docs/3.x/widgets/charts https://filamentphp.com/docs/3.x/widgets/adding-a-widget-to-a-blade-view
toeknee
toeknee2w ago
Yeah that won't work really, DomDPF isn't complex enough to handle that level of complextiy rendering in html/css to the best of my knowlage. I think what you need to do is browser shot it. Or use something like API2PDF (Dan recommends too) whereby you have a temporary URL that renders the HTML/ page as you want in PDF Form and just take a snap of the page.
Lucas de Mello
Lucas de MelloOP2w ago
I'm trying to do this, to test a create a second Route: The First route -> Print the blade template as PDF The Second route -> Returns the View without transformation in PDF The Html route print the Chart but when the lib translate de HTML to PDF not
No description
Matthew
Matthew2w ago
Yeah, theoretically it should work, but as @toeknee said, dompdf just isnt complex enough to handle it... Not sure if its possible unfortunately
Lucas de Mello
Lucas de MelloOP2w ago
Uhmm Ok, I didn't really understand the solution, how it works to make my browser shot it? I'm thinking it will be easier to find a JS framework that creates this graph again.
Matthew
Matthew2w ago
Because blade can render it, but dompdf cant convert the chart from html to PDF
toeknee
toeknee2w ago
Im use a JS Framework to take a screenshot but it's temperamental with sizing as to where the graphs fit. I would suggest revieiw howing api2pdf works or spaties browsershot plugin works the chart is built in JS and the JS isn't rendered in domPDF

Did you find this page helpful?