Questions tagged «itext»


1
使用Spring MVC返回生成的pdf
我正在使用Spring MVC。我必须编写一个服务,该服务将从请求主体中获取输入,将数据添加到pdf中,然后将pdf文件返回到浏览器。pdf文档是使用itextpdf生成的。如何使用Spring MVC做到这一点。我试过使用这个 @RequestMapping(value="/getpdf", method=RequestMethod.POST) public Document getPDF(HttpServletRequest request , HttpServletResponse response, @RequestBody String json) throws Exception { response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment:filename=report.pdf"); OutputStream out = response.getOutputStream(); Document doc = PdfUtil.showHelp(emp); return doc; } 生成pdf的showhelp函数。我只是暂时将一些随机数据放入pdf中。 public static Document showHelp(Employee emp) throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("C:/tmp/report.pdf")); document.open(); …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.