Problem TCPDF automatically added html extension to the PDF file in android browser

46 Views Asked by At

Here my code

in contoller

TCPDF::writeHTML($html_content, true, false, true, false, ''); 
return TCPDF::Output('test.pdf', 'D');

in blade

<a href="/tes.pdf" type="button" target="_self">Download</a>

The problem only in android phone after downloaded file become 'test.pdf.html', any solution?

1

There are 1 best solutions below

1
Karl Hill On BEST ANSWER

You can modify your controller code to output the PDF as a string and then return a response with the correct headers.

$pdf = new TCPDF();
$pdf->writeHTML($html_content, true, false, true, false, '');
$pdfContent = $pdf->Output('test.pdf', 'S');

return response($pdfContent, 200, [
    'Content-Type' => 'application/pdf',
    'Content-Disposition' => 'attachment; filename="test.pdf"',
]);