Search code examples
phppdfwkhtmltopdf

Knp\Snappy\Pdf generateFromHTML not generating the PDF with correct filename


I have PDF download functionality in my Laravel application.

It works perfectly when the PDF filename is English, the problem is with other languages.

$pdf = new Pdf();
...
$pdf->generateFromHtml(View::make('invoices.download'.$preferences->invoice_template, $data), $pdf_file_loc);
return Response::download($pdf_file_loc);

In the above code, $pdf_file_loc has a full path of PDF file as well as the PDF filename. Currently, for instance, when the filename is "Förderverein_für.pdf" (it is German), the real name of created PDF file is "Frderverein_fr.pdf".

In other words, the generateFromHtml function is not creating the PDF file with correct German filename.

But after that, as $pdf_file_loc is containing the correct German name, it is trying to download the "Förderverein_für.pdf" file which isn't exist (in the return Response::download($pdf_file_loc)).

So it is showing an error page when I try to download the PDF file

This is causing a serious problem in my live application as the PDF filename contains our customer's company name and it is often written by foreign languages (not English).


Solution

  • As the generateFromHtml function is not creating the file with other languages (not English), I didn't include other languages in the filename but tried to reset the filename with other language while downloading the file.

    So, now the $pdf_file_loc doesn't include other language and it is stored with only English in the app store but convert it to other language while downloading.

    return Response::download($pdf_file_loc, $filename);
    

    I don't think this is best answer but as long as the purpose is to get the PDF filename with other language, this solves my problem.