在没有下载提示的情况下在浏览器中查看pdf


View pdf in browser without download prompt

Firefox每次都提示下载PDF文件,但Chrome在没有下载提示的情况下在浏览器中显示PDF,但是我需要在任何浏览器中显示PDF而没有下载提示,有人可以帮助我吗?

这是代码

$file = 'the_pdf.pdf';

header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $file . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
@readfile($file);

这将基于插件。 如果浏览器不知道如何打开文件,那么它将提示下载它。

"在任何浏览器中显示PDF":你不能,因为大多数浏览器允许通过某些设置覆盖插件的内联显示。例如,My Opera总是打开带有下载对话框的PDF链接。Web开发人员对此无能为力。这是有意的。