【问题标题】:View pdf file in browser instead of downloading在浏览器中查看 pdf 文件而不是下载
【发布时间】:2016-01-20 04:17:01
【问题描述】:
header("Content-Length: " . filesize ('theme/assets/pdf/ci.pdf' ) ); 
header("Content-type: application/pdf"); 
header("Content-disposition: attachment;     
filename=".basename('theme/assets/pdf/ci.pdf'));
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
$filepath = readfile('theme/assets/pdf/ci.pdf');

嗨朋友们,我有这种类型的代码。我的要求是我必须在浏览器中显示加载的 pdf(在浏览器中打开 pdf),但现在 pdf 已下载到硬盘。相反,我想在浏览器中查看文件。

【问题讨论】:

  • 你在用dompdf吗
  • @AdarshMPallickal 不,我没有使用它
  • 使用内联代替附件
  • @AdarshMPallickal 是的,它的工作非常感谢大家
  • @AdarshMPallickal 你能告诉我如何将这个加载的 PDF 转换成图像

标签: php codeigniter fpdf


【解决方案1】:

您需要将Content-disposition 更改为inline

改变

header("Content-disposition: attachment;     
filename=".basename('theme/assets/pdf/ci.pdf'));

收件人:

header("Content-disposition: inline;     
filename=".basename('theme/assets/pdf/ci.pdf'));

【讨论】:

    【解决方案2】:

    PDF 文件的下载或打开取决于浏览器中的设置。

    浏览器设置打开 PDF 文件而不是下载:

    在 Chrome 中打开 PDF 在您的计算机上,打开 Chrome。 点击右上角的更多设置。 在底部,单击高级。 在“隐私和安全”下,点击内容设置。 在底部附近,单击 PDF 文档。 关闭下载 PDF 文件,而不是在 Chrome 中自动打开它们。

    Mozilla Firefox 中的设置

    1. 单击极右 3 行。
    2. 点击选项
    3. 在一般选择中转到应用程序
    4. 将 PDF 文件设置为“在 Firefox 中预览”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-11
      • 2013-02-21
      • 2013-08-22
      • 2021-07-31
      • 1970-01-01
      • 1970-01-01
      • 2019-04-03
      相关资源
      最近更新 更多