1、首先把 Office 转成 PDF,转换方法(http://www.cnblogs.com/zhiqsyr/p/7240432.html)
2、直接向前端返回 PDF 流
File file = new File(output); // "/Users/zhiqsyr/Downloads/已注册的手机号170717.pdf" resp.setContentType("application/pdf"); resp.setHeader("Content-Disposition", "inline; filename=" + URLEncoder.encode(file.getName(), "UTF-8")); BufferedInputStream br = new BufferedInputStream(new FileInputStream(file)); byte[] buf = new byte[1024]; int len = 0; OutputStream out = resp.getOutputStream(); while ((len = br.read(buf)) > 0) out.write(buf, 0, len); br.close(); out.close();
3、前端集成 pdf.js 支持展示