REST Web服务方法,用于在浏览器中显示pdf文件 [英] REST web services method to display pdf file in browser

查看:367
本文介绍了REST Web服务方法,用于在浏览器中显示pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是这个REST的REST Web服务的新手,我正在做一些小例子,我在生成PDF文件时遇到了问题。以下方法用于生成PDF文件。


I am new to the REST web services with this REST am doing some small examples, and i have a problem with producing PDF file. following method am using to produce PDF file.

@GET
@Produces("application/pdf")
public Response ReadPDF() {
    File file = new File("fileName.pdf");
    ResponseBuilder response = Response.ok((Object) file);
    response.header("Content-Disposition",  "attachment; filename=restfile.pdf");
    return response.build();
}

这种方法工作正常并提供pdf文件下载,所以随叫随到REST方法浏览器询问(保存或打开)选项。但是我想默认在浏览器中显示PDF文件。

this method working fine and provides pdf file to download, so on call of this REST method browser asking (save or open) option. but i wanted to display the PDF file in browser by default.

推荐答案

这部分取决于是否插件(通常是Acrobat Reader插件) )已安装。此外,您不应使用 Content-Disposition:attachment (正如您现在使用的那样)。

This partly depends on whether a plugin (typically Acrobat Reader plugin) is installed. In addition, you shouldn't use Content-Disposition: attachment (as you're using now).

请参阅本文的疑难解答部分

这篇关于REST Web服务方法,用于在浏览器中显示pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆