/** * @Author gzg * @Decription // TODO * @Date 2024/4/22 9:41 * @param * @return */ @ApiOperation(value = "pdf查看", notes = "pdf查看") @ApiImplicitParams({ @ApiImplicitParam(name = "path", value = "path", required = true, dataType = "String") }) @RequestMapping(value = "/viewPdf",method = RequestMethod.GET) public void viewPdf(HttpServletResponse response,String path){ File file = new File(path); if (file.exists()){ try { FileInputStream fileInputStream = new FileInputStream(file); response.setHeader("Content-Type", "application/pdf"); OutputStream outputStream = response.getOutputStream(); IOUtils.write(IOUtils.toByteArray(fileInputStream), outputStream); outputStream.flush(); outputStream.close(); fileInputStream.close(); } catch (Exception e) { System.out.println(e); } }else{ return; } } }
pdf 浏览器查看
最新推荐文章于 2024-11-11 20:11:28 发布
该代码片段展示了如何通过Java编写一个RESTfulAPI,使用HttpServletRequest来提供PDF文件的在线查看功能,通过设置Content-Type头并读取文件内容发送给用户。
摘要由CSDN通过智能技术生成