1.将所需的两个文件夹放入WEB目录下
2.
在前台调用VIEWER.HTML页面。
(1)若为本地文件,直接通过相对路径调用如:
window.open("../pages/web/viewer.html?file=./测试.pdf");
(2)若调用其他服务器的文件,则传入下载的URL地址(此地址直接输入浏览器应可直接下载文件)
window.open("../pages/web/viewer.html?file="+encodeURIComponent(ctxPre+"/user/salebybkdtl/convert1?filePath="+filePath));
需先通过后台将URL转换成流输入,后台代码如下:
@ResponseBody
@RequestMapping(value = "/convert1")
@HeadInit(name = HeadConstants.HEAD_SCENE, value = "Cst")
public String getPdfInfo(HttpServletRequest request, HttpServletResponse response, @RequestParam String filePath) throws IOException {
String pdfUrl = filePath;
URL url;
try {
url = new URL(pdfUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5 * 1000);
InputStream inputStream = conn.getInputStream();
response.setHeader("Content-Disposition", "attachment;fileName=结业.pdf");
response.setContentType("multipart/form-data");
OutputStream outputStream = response.getOutputStream();
IOUtils.write(IOUtils.toByteArray(inputStream), outputStream);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
IOUtils用的是org.apache.commons.io.IOUtils
最后感谢大佬https://blog.csdn.net/tao111369/article/details/79714154