Skip to content

Is there other way to create pdf in php?

Hello I’ve got a problem with my page, cuz I want to generate PDF file async with jquery, command:

   $.get('/pl/home/generujPDF', function( data ) {      

In my controller it looks somethink like this

function generujPDF()
    require_once 'vendor/autoload.php';
    $mpdf = new MpdfMpdf();
    $mpdf->WriteHTML('<h1>Hello world!</h1>');
    $mpdf->Output("mpdf.pdf", "D");exit;


And that doesn’t work, But if I type in URL /pl/home/generujPDF it just work fine. I check how it looks in “Network” tab in browser and I have 2 other types of this URL- … document (working fine) and xhr(it doesn’t work) Network Tab How to fix that, Thank you in advance 🙂



Try to use tag with download attribute and click programmatically.

<a href="/pl/home/generujPDF" download class="download-pdf"></a>

$(function() {

Maybe it works


You can see more answers here: Download and open PDF file using Ajax

User contributions licensed under: CC BY-SA
10 People found this is helpful