@RequestMapping(path = "/file", method = RequestMethod.GET)
public void test(HttpServletResponse response) throws IOException {
String str ="D:/1.pdf";
FileInputStream fileInputStream= new FileInputStream(str);
response.addHeader("Content-Disposition", "attachment; filename=" + str.substring(str.lastIndexOf("/") + 1));
response.setContentType("application/pdf");
byte[] bytes = new byte[fileInputStream.available()];
int i;
if ( (i = fileInputStream.read(bytes)) > 0){
response.getOutputStream().write(bytes, 0, i);
}
}
这种方式浏览器显示的title就是 file,而不是1.pdf,请问怎么才能让它显示成自定义的标题呢?
response.addHeader("Content-Disposition", "attachment; filename=" + str.substring(str.lastIndexOf("/") + 1));
这个定义用在下载文件上的,我把attachment改成inline也显示不出来
https://blog.csdn.net/shy_1762538422/article/details/113663650 这是解决方案
使用第三方的插件去做pdf预览,尽量别直接用浏览器预览;
直接依靠浏览器预览,浏览器不同,展示效果不同(所以就可能出现你这种情况);
我们线上用的是pdf.js,