java导出PDF详细教程+各种踩坑
直接上代码了
所需依赖:
<dependency> <groupId>com.itextpdf</groupId> <artifactId>itextpdf</artifactId> <version>5.4.3</version> </dependency> <dependency> <groupId>com.itextpdf</groupId> <artifactId>itext-asian</artifactId> <version>5.2.0</version> </dependency>
控制层代码:
@RequestMapping("/downloadLogPDF") public void downloadLogPDF(HttpServletRequest request, HttpServletResponse response) { tLogService.downloadLogPDF(request, response); }
实现类代码:
@Override public void downloadLogPDF(HttpServletRequest request, HttpServletResponse response) { //解析request中的请求参数 String interfaceType = request.getParameter("interfaceType"); String startDate = request.getParameter("startDate"); String endDate = request.getParameter("endDate"); List<Map<String, Object>> dataResult = getLogListByType(interfaceType, startDate, endDate); String fileName = "日志报表_" + startDate.split(" ")[0].toString() + "~" + endDate.split(" ")[0].toString() + ".pdf"; String path = System.getProperty("user.dir") + "/downLoad/"; //设置基础中文字体 BaseFont bfChinese = null; try
原文地址:https://blog.csdn.net/weixin_43952697/article/details/140471334
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!