从Slim Framework下载PDF时我没有设置pdf名称因为我已经通过PDF设置选项指定了pdf的名称
喜欢这个:
<?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'));
?>
但是通过分配通过html传递的路由名称来下载文件。
示例网址:http://localhost:8080/collections/getBranchWisePDF/1
如果param设置为1,则文件名为1,分配给pdf并下载文件
使用TCP Pdf和Slim Framework更改pdf名称的任何选项。
提前致谢
答案 0 :(得分:2)
我不知道您使用哪个库来处理PDF文件,因此我无法完全理解$pdf->Output('My_cool_PDF.pdf', 'S')
部分,但您可以尝试通过在响应中发送附加标头来设置文件名:
<?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'));
?>