Slim Framework name for PDF name

I am not getting the name of the PDF when I download the PDF from Slim Framework as I have assigned a name to the PDF using the PDF options.

Like this:

<?php
    $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
    $response = $this->response->withHeader('Content-type', 'application/pdf');
    $response->write($pdf->Output('My_cool_PDF.pdf', 'S'));
?>

      

But the file is loaded by assigning a name to the route name passed through the html.

Example URL: http: // localhost: 8080 / collections / getBranchWisePDF / 1

If the parameter is set to 1, the filename is 1, which is assigned in the pdf and the file is loaded

any options to rename PDF using TCP Pdf and Slim Framework.

Thank you in advance

+3


source to share


1 answer


I don't know which library you are using to handle PDF files, so I cannot fully understand the part $pdf->Output('My_cool_PDF.pdf', 'S')

, but you can try setting the filename by sending an additional header with a response:



<?php
    $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
    $response = $this->response->withHeader('Content-type', 'application/pdf')
        // Here we appned another header to let the browser know about the file name
        ->withAddedHeader('Content-Disposition', 'attachment; filename=My_cool_PDF.pdf');
    $response->write($pdf->Output('My_cool_PDF.pdf', 'S'));
?>

      

+1


source







All Articles