在 Safari 5.1.7 中下载 PDF 文件
Posted
技术标签:
【中文标题】在 Safari 5.1.7 中下载 PDF 文件【英文标题】:download PDF file in safari 5.1.7 【发布时间】:2013-03-20 07:23:29 【问题描述】:我正在使用 cakephp。我已经使用来自 http://koivi.com/fill-pdf-form-fields 这个 URL 的函数生成了 FDF
文件
它工作正常。然后我使用PDFTK
生成 PDF 文件,并有一些标题来下载该文件,它在 Firefox、Chorome 和 IE 中运行良好,但在 safari 浏览器中运行不佳。在 Safari 中,它显示 PDF 文件代码。当我在命令末尾使用exit();
时,Safari 会下载文件,但它并不完整。
文件的正常大小是 60Kb,但使用 exit()
它会生成 48Kb 的文件。所以这意味着由于exit()
命令而丢失了一些PDF
文件内容。
如果有人可以给出一些提示以在 safari 浏览器中解决此问题。 提前致谢。
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="pdf_file_name.pdf"');
header("Content-Type: application/download");
header("Content-Length: " . filesize($pdf_doc));
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
// $pdf_doc is the PDF Form physical path
// $fdf_doc is the FDF file physical path
echo passthru("/usr/local/bin/pdftk $pdf_doc fill_form $fdf_doc output - ");
【问题讨论】:
我注意到,当 PDF 代码显示在 safari 中并点击刷新按钮时,它会提供文件下载选项。 【参考方案1】:使用PDFTK的以下命令将生成的文件保存在磁盘上
passthru("pdftk $pdf_doc fill_form $fdf_doc output test.pdf");
然后对已生成的PDF
使用与您相同的代码。
保存PDF
文件后试试下面的代码
header('Content-Disposition: attachment; filename="pdf_file_name.pdf"');
header("Content-Type: application/download");
header('Content-Type:application/pdf');
header("Content-Length: " . filesize("test.pdf"));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
readfile("test.pdf");
希望这也适用于野生动物园
【讨论】:
【参考方案2】:试试header('Content-Type:application/pdf');
【讨论】:
我认为是 Safari 错误,discussions.apple.com/thread/3906040?start=0&tstart=0以上是关于在 Safari 5.1.7 中下载 PDF 文件的主要内容,如果未能解决你的问题,请参考以下文章
mac火狐浏览器下载中国知网的pdf文稿,文件名称为啥是乱码?用safari下载文献正常的。配图
在 Swift 4.2 Xcode 10 中使用动作扩展从 Safari 共享 PDF 文件失败