How do I force files to open in the browser instead of downloading (PDF)?

后端 未结 13 1268
别跟我提以往
别跟我提以往 2020-11-22 04:15

Is there a way to force PDF files to open in the browser when the option \"Display PDF in browser\" is unchecked?

I tried using the embed tag and an iframe, but it o

13条回答
  •  一生所求
    2020-11-22 05:08

    To indicate to the browser that the file should be viewed in the browser, the HTTP response should include these headers:

    Content-Type: application/pdf
    Content-Disposition: inline; filename="filename.pdf"
    

    To have the file downloaded rather than viewed:

    Content-Type: application/pdf
    Content-Disposition: attachment; filename="filename.pdf"
    

    The quotes around the filename are required if the filename contains special characters such as filename[1].pdf which may otherwise break the browser's ability to handle the response.

    How you set the HTTP response headers will depend on your HTTP server (or, if you are generating the PDF response from server-side code: your server-side programming language).

提交回复
热议问题