Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nikolov.inn's avatar

Export Laravel Charts to PDF

Hi there,

I am creating database charts using the Laravel Charting Package and it works great. After that I want to export the generated chart using Laravel DOMPDF. The PDF is created but it remains blank... This is what I have in my controller:

class PDFController extends Controller { public function getPDF(){ $chart = Charts::database(User::all(),'bar', 'material') // Setup the chart settings ->groupBy('username'); // Setup what the values mean

    $pdf=PDF::loadView('test', ['chart' => $chart]);
    return $pdf->stream('test.pdf');
}

}

and the view:

    <title>My Charts</title>

    {!! Charts::assets() !!}

</head>
<body>
    <center>
        {!! $chart->render() !!}
    </center>
</body>

Thanks!

0 likes
2 replies
mushketer888's avatar

PDF can't understand Javascript,HTML5 etc...You need somehow to generate image and inject it in PDF. (use another lib to export chart to image)

Please or to participate in this conversation.