简体   繁体   English

如何在Windows浏览器中或浏览器外部显示生成的PDF文件?

[英]How to show a generated PDF file with in the browser or outside the browser in windows?

In my application, I want show a printable PDF acrobat file with in the browser or outside the browser other than saving. 在我的应用程序中,除了保存之外,我还希望在浏览器中或浏览器外部显示可打印的PDF acrobat文件。 In Firefox by default it will ask for save or open, I don't need that dialogue. 默认情况下,在Firefox中,它将要求保存或打开,我不需要该对话框。 I want to show that file preferably outside the browser. 我想最好在浏览器之外显示该文件。 Can you please suggest me. 你能建议我吗。

Thanks, 谢谢,
Vara Kumar.PJD 瓦拉·库玛

You can suggest to the browser that it should show the PDF in a window rather than offering to download it via the Content-Disposition header : 您可以向浏览器建议它应该在窗口中显示PDF,而不是通过Content-Disposition标头提供下载:

response.addHeader("Content-Disposition", "inline");

The "inline" value suggests that the content be rendered inline (as opposed to the "attachment" value suggesting the browser offer to download it). “内联”值建议内容以内联方式呈现(与“附件”值建议浏览器提供下载内容相反)。

Once you've made the suggestion to the browser, the browser may or may not accept your suggestion, depending on its implementation and possibly its user preferences. 向浏览器提出建议后,浏览器可能会接受或可能不会接受您的建议,具体取决于其实现方式以及用户的偏好。

我不认为这是您可以从您的应用程序中控制的事情,我认为这是用户正在使用的环境/浏览器/插件的问题...但是zou可以通过javascript这样的链接为您的pdf打开新窗口

You can do like some thing like this. 您可以喜欢这样的事情。

        response.setContentType("application/pdf"); 
        InputStream in = new FileInputStream("answerconnect.pdf"); 
        OutputStream out = response.getOutputStream(); 
        byte[] buf = new byte[1024]; 
        int len; 
        while ((len = in.read(buf)) > 0) { 
            out.write(buf, 0, len); 
        } 
        in.close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM