从 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
如果参数设置为 1,则文件名是 1,它被分配给 pdf 并且文件被下载
使用 TCP Pdf 和 Slim Framework 更改 pdf 名称的任何选项。
提前致谢
最佳答案
我不知道您使用哪个库来处理 PDF 文件,所以我无法完全理解 $pdf->Output('My_cool_PDF.pdf', 'S')
部分,但您可以尝试通过在响应中发送附加 header 来设置文件名:
<?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'));
?>
关于php - Slim Framework 为 PDF 设置名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45343957/