【问题标题】:download PDF file in safari 5.1.7在 Safari 5.1.7 中下载 PDF 文件
【发布时间】: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 中并点击刷新按钮时,它会提供文件下载选项。

标签: cakephp pdf safari download


【解决方案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');

    【讨论】:

    猜你喜欢
    • 2015-06-03
    • 1970-01-01
    • 2011-08-12
    • 2021-02-28
    • 2017-07-18
    • 1970-01-01
    • 2015-05-27
    • 1970-01-01
    相关资源
    最近更新 更多