通过ajax在浏览器选项卡中显示pdf
showing pdf in browser tab through ajax
我曾使用jquery.fileDownload和Spring通过Ajax下载.pdf文件。
应用程序运行良好,pdf文件下载成功。问题是,我不想下载pdf,而是想在新的浏览器选项卡中打开。
有人能告诉我这个的一些解决方案吗
服务器端
我在服务器端使用Spring
@RequestMapping(value = "exportPDF", method = RequestMethod.POST, produces = APP_JSON)
@ResponseBody
public void getPDF(final HttpServletResponse response, @RequestParam(value = "empId", required = true) final String empId) throws IOException, Exception
{
final byte[] pdf= ExportPDFUtil.getFileBytes(empId); // get the file bytes
final OutputStream output = getOutputStream(response);
response.setHeader("Content-Disposition", "attachment; filename=documents_" + new DateTime() + ".pdf");
response.setContentType(CONTENT_TYPE);
response.setContentLength(pdf.length);
write(output, pdf);
}
客户端
在客户端,我使用AngularJS
$downloadXLS = function(id)
{
$.fileDownload('/user/exportPDF',
{
httpMethod : "POST",
data : {
empId : id
}
}).done(function(e, response)
{
// success
}).fail(function(e, response)
{
// failure
});
}
查看Mozilla的PDF.js。大多数应用程序都使用它在浏览器中显示PDF。
尝试使用这个:
response.setHeader("Content-Disposition", "inline;
filename=documents_" + new DateTime() + ".pdf");
而不是:
response.setHeader("Content-Disposition", "attachment;
filename=documents_" + new DateTime() + ".pdf");
相关文章:
- 如何使用jquery在工具提示上显示pdf文件
- 通过发送POST参数在ExtJS 4中显示PDF
- 我想在灯箱中显示pdf文档
- window.open无法在显示pdf的jsp页面中工作
- 如何从输入字段在浏览器中显示PDF文件
- 在新窗口中显示pdf流
- jqGrid-单击链接时在新窗口中显示PDF
- 如何发布到URL并打开一个新窗口以显示pdf格式的响应
- 在phonegap应用程序中显示pdf
- 使用pdf.js突出显示pdf中的一个部分
- 在网络上显示 PDF,但不可下载
- 如何在显示 pdf 文件之前加载加载程序图像
- 浏览器请求文件,服务器下载 pdf,浏览器在 iframe 中显示 pdf
- 如何使用javascript在浏览器中显示PDF流
- 在iframe PHP中显示pdf
- 如何使用RESTful/ajax/js在UI上显示PDF,使用来自UI的表单输入
- 我需要一个显示pdf的解决方案
- Angular-下载并显示PDF
- 在浏览器中只显示PDF一次,然后将其从C#服务器中删除
- 通过ajax在浏览器选项卡中显示pdf