×

浏览器打开pdf格式文件自动预览

hqy hqy 发表于2025-03-13 19:41:04 浏览196 评论0

抢沙发发表评论

  有一朋友需打开Web服务器(nginx)中pdf格式文件实现自动预览--缺省为下载文件,于是网上查阅了些资料,发现是一个名为Content-Disposition的HTTP头部在控制:

nginx 服务器

Nginx服务器为例:

    server {
        listen       8080;
        server_name  _;
        root         /usr/share/nginx/html;

        location ~* \.(pdf|txt|log)$ {
            add_header Content-Disposition inline;
            #add_header Content-Disposition attachment;
           }
        }
  • inline: 自动预览动作

  • attachment: 下载动作

Apache 服务器

<FilesMatch "\.(?i:pdf)$">
      ForceType application/octet-stream
      Header set Content-Disposition attachment
</FilesMatch>

预览

经过测试 Chrome、Firefox 皆正常

02

注意要点

  • 文件名尽量不使用中文

参考引用




推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

本文链接:https://www.jinbel.cn/post/9545.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:
打赏

群贤毕至

访客

您的IP地址是: