导入依赖
<!-- pdf--> <dependency> <groupId>com.itextpdf</groupId> <artifactId>itextpdf</artifactId> <version>5.5.13</version> </dependency> <dependency> <groupId>com.itextpdf</groupId> <artifactId>font-asian</artifactId> <version>7.1.2</version> <scope>test</scope> </dependency> <dependency> <groupId>com.itextpdf</groupId> <artifactId>itext-asian</artifactId> <version>5.2.0</version> </dependency>
package gsa.rule.model.util;
import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Value;
import com.itextpdf.text.BaseColor; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.Font; import com.itextpdf.text.PageSize; import com.itextpdf.text.Paragraph; import com.itextpdf.text.Phrase; import com.itextpdf.text.pdf.AcroFields; import com.itextpdf.text.pdf.BaseFont; import com.itextpdf.text.pdf.PdfArray; import com.itextpdf.text.pdf.PdfContentByte; import com.itextpdf.text.pdf.PdfDictionary; import com.itextpdf.text.pdf.PdfName; import com.itextpdf.text.pdf.PdfObject; import com.itextpdf.text.pdf.PdfPCell; import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfReader; import com.itextpdf.text.pdf.PdfStamper; import com.itextpdf.text.pdf.PdfWriter;
import gsa.base.common.Utils.Utils;
public class PdfUtil { @Value("${nginx.localfilepath}") private String filepath; @Value("${nginx.localfileurl}") private String fileurl; /** * 抠模板 * @throws Exception */ public static void createAllPdf() throws Exception { //填充创建pdf PdfReader reader = null; PdfStamper stamp = null; try { reader = new PdfReader("D:/惠州监管平台/2020年7月 惠州市建设项目用地报批评估报告.pdf"); SimpleDateFormat simp = new SimpleDateFormat("yyyy-MM-dd"); String times = simp.format(new Date()).trim(); //创建生成报告名称 // String root = ServletActionContext.getRequest().getRealPath("/upload") + File.separator; // if (!new File(root).exists()) // new File(root).mkdirs(); // File deskFile = new File(root, times + ".pdf"); File path = new File("D:/HZJGPT/" + times + ".pdf"); BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); // set font Font font = new Font(bf,10); // FileManagerUtil.uploadFiles(file, filepath); stamp = new PdfStamper(reader, new FileOutputStream(path)); //取出报表模板中的所有字段 AcroFields form = stamp.getAcroFields(); for (int i=1; i<=reader.getNumberOfPages(); i++){ //获得pdfstamper在当前页的上层打印内容.也就是说 这些内容会覆盖在原先的pdf内容之上. PdfContentByte over = stamp.getOverContent(i); //用pdfreader获得当前页字典对象.包含了该页的一些数据.比如该页的坐标轴信息. PdfDictionary p = reader.getPageN(i); //拿到mediaBox 里面放着该页pdf的大小信息. PdfObject po = p.get(new PdfName("MediaBox")); System.out.println(po.isArray()); //po是一个数组对象.里面包含了该页pdf的坐标轴范围. PdfArray pa = (PdfArray) po; System.out.println(pa.size()); //看看y轴的最大值. System.out.println(pa.getAsNumber(pa.size()-1)); //开始写入文本 over.beginText(); //设置字体和大小 over.setFontAndSize(font.getBaseFont(), 10); //设置字体的输出位置 over.setTextMatrix(107, 540); //要输出的text over.showText("我要加[终稿]字样 " + i); over.endText(); //创建一个image对象. /*Image image = Image.getInstance("c:/1.jpg"); //设置image对象的输出位置pa.getAsNumber(pa.size()-1).floatValue() 是该页pdf坐标轴的y轴的最大值 image.setAbsolutePosition(0,pa.getAsNumber(pa.size()-1).floatValue()-100);//0, 0, 841.92, 595.32 over.addImage(image);*/ //画一个圈. over.setRGBColorStroke(0xFF, 0x00, 0x00); over.setLineWidth(5f); over.ellipse(250, 450, 350, 550); over.stroke(); } stamp.close();
// 填充数据 form.setField("fpzs", "123"); form.setField("ysyzs", "123"); form.setField("syzs", "15");
//报告生成日期 SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd"); String generationdate = dateformat.format(new Date()); form.setField("generationdate", generationdate); stamp.setFormFlattening(true); } catch (Exception e) { e.printStackTrace(); } finally { if (stamp != null) { stamp.close(); } if (reader != null) { reader.close(); } } } public static void pdf() throws DocumentException, IOException { String zb="惠州市2020年度用地计划指标共计fpzs亩,已使用指标ysyzs亩,剩余syzs亩,使用率syl。其中,新增建设用地计划指标fpxzzs亩,已使用ysyxzzs亩,剩余syxzzs亩,使用率xzsyl;复垦周转指标fpfkzs亩,已使用ysyfkzs亩,剩余syfkzs亩,使用率fksyl;增减挂钩指标fpzjzs亩,已使用ysyzjzs亩,剩余syzjzs亩,使用率zjsyl。"; String zb1="惠州市xxxx年xx月,已完成组卷的用地报批面积共计xxx亩。其中,报批的农用地xxx亩,耕地xxx亩,基本农田xxx亩,未利用地xxx亩。正在报批的面积xxx亩,其中:农用地xxx亩,耕地xxx亩,基本农田xxx亩,未利用地xxx亩;已报批面积xxx亩,其中:农用地xxx亩,耕地xxx亩,基本农田xxx亩,未利用地xxx亩。"; String zb2="惠州市xxxx年xx月,已完成组卷的用地报批面积共计xxx亩。其中,单独选址项目用地报批面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%;批次用地报批面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%;城市建设用地农用地转用和土地征收实施方案报批面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%;“只转不征”项目用地报批面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%;报国务院批准的城市建设用地(一年一批次)面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%。各区县报批类型统计情况见下表:"; String zb3="惠州市xxxx年xx月,已完成组卷的用地报批面积共计xxx亩,工业用地xxx亩,工业用地占比xx%。其中,商服用地报批面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%;住宅用地报批面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%;工矿仓储用地报批面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%;其他用地报批面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%。各区县开发用途统计情况见下表:"; // Document document =new Document(); // 默认页面大小是A4 // Document document =new Document(PageSize.A4); // 指定页面大小为A4 String times = Utils.getRandomStr(5); Document document =new Document(PageSize.A4,50,50,100,20); // 指定页面大小为A4,且自定义页边距(marginLeft、marginRight、marginTop、marginBottom) PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("D:/HZJGPT/" + times + ".pdf")); document.open(); BaseFont bfChinese; bfChinese=BaseFont.createFont("STSongStd-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);//jar包 // bfChinese=BaseFont.createFont("C:/Windows/Fonts/msyh.ttf",BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED); //系统字体,其实5.0版以后的iText加入字体还是很方便的。 Font topfont = new Font(bfChinese,14,Font.NORMAL); Font textfont =new Font(bfChinese,10,Font.BOLD|Font.UNDERLINE); Font font = new Font(bfChinese, 12); Font bigtitielFont = new Font(bfChinese, 18, Font.BOLD);//设置字体 Font titielFont = new Font(bfChinese, 22, Font.BOLD);//设置字体 Font dateFont = new Font(bfChinese, 22, Font.NORMAL);//设置字体 Font FontChinese = new Font(bfChinese, 16, Font.NORMAL); Paragraph elements = new Paragraph("惠州市建设项目用地报批评估报告", titielFont); elements.setAlignment(Paragraph.ALIGN_CENTER); document.add(elements); Paragraph pdate = new Paragraph("(2020年7月)", dateFont); pdate.setAlignment(Paragraph.ALIGN_CENTER); pdate.setSpacingAfter(40f); document.add(pdate); Paragraph p1=new Paragraph("一、报批情况汇总",bigtitielFont);//设置字体样式 p1.setAlignment(3);//设置文字居中 0靠左 1,居中 2,靠右 p1.setFirstLineIndent(24);// 首行缩进 p1.setLeading(35f); //行间距 document.add(p1); Paragraph p2=new Paragraph("(一) 指标分配及使用情况",FontChinese);//设置字体样式 p2.setAlignment(3);//设置文字居中 0靠左 1,居中 2,靠右 p2.setFirstLineIndent(24);// 首行缩进 p2.setLeading(35f); //行间距 document.add(p2); Paragraph pt=new Paragraph(zb,FontChinese);//设置字体样式 pt.setAlignment(3);//设置文字居中 0靠左 1,居中 2,靠右 // pt.setIndentationLeft(12);// 左缩进 // pt.setIndentationRight(12);// 右缩进 pt.setFirstLineIndent(24);// 首行缩进 pt.setLeading(35f); //行间距 // pt.setSpacingBefore(5f); //设置段落上空白 // pt.setSpacingAfter(10f); //设置段落下空白 // File path = new File("D:/HZJGPT/" + times + ".pdf"); document.add(pt);
// 5.关闭文档 document.close(); } public static void generatePdf() throws DocumentException, IOException { String zb="惠州市2020年度用地计划指标共计fpzs亩,已使用指标ysyzs亩,剩余syzs亩,使用率syl。其中,新增建设用地计划指标fpxzzs亩,已使用ysyxzzs亩,剩余syxzzs亩,使用率xzsyl;复垦周转指标fpfkzs亩,已使用ysyfkzs亩,剩余syfkzs亩,使用率fksyl;增减挂钩指标fpzjzs亩,已使用ysyzjzs亩,剩余syzjzs亩,使用率zjsyl。"; String zb1="惠州市xxxx年xx月,已完成组卷的用地报批面积共计xxx亩。其中,报批的农用地xxx亩,耕地xxx亩,基本农田xxx亩,未利用地xxx亩。正在报批的面积xxx亩,其中:农用地xxx亩,耕地xxx亩,基本农田xxx亩,未利用地xxx亩;已报批面积xxx亩,其中:农用地xxx亩,耕地xxx亩,基本农田xxx亩,未利用地xxx亩。"; String zb2="惠州市xxxx年xx月,已完成组卷的用地报批面积共计xxx亩。其中,单独选址项目用地报批面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%;批次用地报批面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%;城市建设用地农用地转用和土地征收实施方案报批面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%;“只转不征”项目用地报批面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%;报国务院批准的城市建设用地(一年一批次)面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%。各区县报批类型统计情况见下表:"; String zb3="惠州市xxxx年xx月,已完成组卷的用地报批面积共计xxx亩,工业用地xxx亩,工业用地占比xx%。其中,商服用地报批面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%;住宅用地报批面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%;工矿仓储用地报批面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%;其他用地报批面积xxx亩,去年同期xxx亩,上月xxx亩,同比增加/减少xx%,环比增加/减少xx%。各区县开发用途统计情况见下表:"; String times = Utils.getRandomStr(5); Document document =new Document(PageSize.A4,50,50,100,20); // 指定页面大小为A4,且自定义页边距(marginLeft、marginRight、marginTop、marginBottom) PdfWriter.getInstance(document, new FileOutputStream("D:/HZJGPT/" + times + ".pdf")); document.open(); BaseFont bfChinese; bfChinese=BaseFont.createFont("STSongStd-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);//jar包 Font topfont = new Font(bfChinese,14,Font.NORMAL); Font textfont =new Font(bfChinese,10,Font.BOLD|Font.UNDERLINE); Font font = new Font(bfChinese, 12); Font bigtitielFont = new Font(bfChinese, 18, Font.BOLD);//设置字体 Font titielFont = new Font(bfChinese, 22, Font.BOLD);//设置字体 Font dateFont = new Font(bfChinese, 22, Font.NORMAL);//设置字体 Font FontChinese = new Font(bfChinese, 16, Font.NORMAL); Paragraph elements = new Paragraph("惠州市建设项目用地报批评估报告", titielFont); elements.setAlignment(Paragraph.ALIGN_CENTER); document.add(elements); //---------------------------------------------------------------------------- Paragraph pdate = new Paragraph("(2020年7月)", dateFont); pdate.setAlignment(Paragraph.ALIGN_CENTER); pdate.setSpacingAfter(40f); document.add(pdate); //-------------------------------------------------------------------- Paragraph p1=new Paragraph("一、报批情况汇总",bigtitielFont);//设置字体样式 p1.setAlignment(3);//设置文字居中 0靠左 1,居中 2,靠右 p1.setFirstLineIndent(24);// 首行缩进 p1.setLeading(35f); //行间距 document.add(p1); //------------------------------------------------------------------------ Paragraph p2=new Paragraph("(一) 指标分配及使用情况",FontChinese);//设置字体样式 p2.setAlignment(3);//设置文字居中 0靠左 1,居中 2,靠右 p2.setFirstLineIndent(24);// 首行缩进 p2.setLeading(35f); //行间距 document.add(p2); //------------------------------------------------------------------------- Paragraph pt=new Paragraph(zb,FontChinese);//设置字体样式 pt.setAlignment(3);//设置文字居中 0靠左 1,居中 2,靠右 pt.setFirstLineIndent(24);// 首行缩进 pt.setLeading(35f); //行间距 document.add(pt); //------------------------------------------------------------------------------ Paragraph p3=new Paragraph("(二) 报批情况实时监控",FontChinese);//设置字体样式 p3.setAlignment(3);//设置文字居中 0靠左 1,居中 2,靠右 p3.setFirstLineIndent(24);// 首行缩进 p3.setLeading(35f); //行间距 document.add(p3); //------------------------------------------------------------------------ Paragraph pt1=new Paragraph(zb1,FontChinese);//设置字体样式 pt1.setAlignment(3);//设置文字居中 0靠左 1,居中 2,靠右 pt1.setFirstLineIndent(24);// 首行缩进 pt1.setLeading(35f); //行间距 document.add(pt1); //------------------------------------------------------------------------ //***************************************************************************** //-------------------------------------------------------------------- Paragraph p4=new Paragraph("二、报批情况专项统计",bigtitielFont);//设置字体样式 p4.setAlignment(3);//设置文字居中 0靠左 1,居中 2,靠右 p4.setFirstLineIndent(24);// 首行缩进 p4.setLeading(35f); //行间距 document.add(p4); //------------------------------------------------------------------------ Paragraph p5=new Paragraph("(一) 按报批类型统计",FontChinese);//设置字体样式 p5.setAlignment(3);//设置文字居中 0靠左 1,居中 2,靠右 p5.setFirstLineIndent(24);// 首行缩进 p5.setLeading(35f); //行间距 document.add(p5); //------------------------------------------------------------------------- Paragraph pt2=new Paragraph(zb2,FontChinese);//设置字体样式 pt2.setAlignment(3);//设置文字居中 0靠左 1,居中 2,靠右 pt2.setFirstLineIndent(24);// 首行缩进 pt2.setLeading(35f); //行间距 document.add(pt2); //------------------------------------------------------------------------------ Paragraph p6=new Paragraph("(二) 按开发用途统计",FontChinese);//设置字体样式 p6.setAlignment(3);//设置文字居中 0靠左 1,居中 2,靠右 p6.setFirstLineIndent(24);// 首行缩进 p6.setLeading(35f); //行间距 document.add(p6); //------------------------------------------------------------------------ Paragraph pt3=new Paragraph(zb3,FontChinese);//设置字体样式 pt3.setAlignment(3);//设置文字居中 0靠左 1,居中 2,靠右 pt3.setFirstLineIndent(24);// 首行缩进 pt3.setLeading(35f); //行间距 document.add(pt3); //------------------------------------------------------------------------
// 5.关闭文档 document.close(); } // double fpzs=zbmap.get("TOTAL"); // double syzs=0.0; // double fpxzzs=0.0; // double ysyxzzs=0.0; // double syxzzs=0.0; // double xzsyl=0.0; // double fpfkzs=0.0; // double ysyfkzs=0.0; // double syfkzs=0.0; // double fksyl=0.0; // double fpzjzs=0.0; // double ysyzjzs=0.0; // double syzjzs=0.0; // double zjsyl=0.0; public static void generatePdf(String year,String month,List<Map<String, Object>> zblist,List<Map<String, Object>> bplist,List<Map<String, Object>> lxlist,List<Map<String, Object>> lxhblist,List<Map<String, Object>> kflist,List<Map<String, Object>> kfhblist,String filepath) throws DocumentException, IOException { Map<String, Object> zbmap=zblist.get(0); Map<String, Object> bpmap=bplist.get(0); Map<String, Object> lxmap=new HashMap<>(); Map<String, Object> lxhbmap=new HashMap<String, Object>(); Map<String, Object> lxtbmap=new HashMap<String, Object>(); for(Map<String, Object> map:lxlist) { if("现期".equals(map.get("TYPE"))&&"全市".equals(map.get("XZQHMC"))) { lxmap=map; }else if("同比".equals(map.get("TYPE"))&&"全市".equals(map.get("XZQHMC"))){ lxtbmap=map; } } for(Map<String, Object> map:lxhblist) { if("环比".equals(map.get("TYPE"))&&"全市".equals(map.get("XZQHMC"))) { lxhbmap=map; } } Map<String, Object> kfmap=new HashMap<>(); Map<String, Object> kfhbmap=new HashMap<String, Object>(); Map<String, Object> kftbmap=new HashMap<String, Object>(); for(Map<String, Object> map:kflist) { if("现期".equals(map.get("TYPE"))&&"全市".equals(map.get("XZQHMC"))) { kfmap=map; }else if("同比".equals(map.get("TYPE"))&&"全市".equals(map.get("XZQHMC"))){ kftbmap=map; } } for(Map<String, Object> map:kfhblist) { if("环比".equals(map.get("TYPE"))&&"全市".equals(map.get("XZQHMC"))) { kfhbmap=map; } } String zb="惠州市"+year+"年度用地计划指标共计"+zbmap.get("TOTAL")+"亩,已使用指标"+zbmap.get("YSY_TOTAL")+"亩,剩余"+zbmap.get("SY_TOTAL")+"亩,使用率"+zbmap.get("TOTAL_SYL")+"。其中,新增建设用地计划指标"+zbmap.get("XZJSYD")+"亩,已使用"+zbmap.get("YSY_XZJSYD")+"亩,剩余"+zbmap.get("SY_XZJSYD")+"亩,使用率"+zbmap.get("XZJSYD_SYL")+";复垦周转指标"+zbmap.get("CJFK")+"亩,已使用"+zbmap.get("YSY_CJFK")+"亩,剩余"+zbmap.get("SY_CJFK")+"亩,使用率"+zbmap.get("CJFK_SYL")+";增减挂钩指标"+zbmap.get("ZJGG")+"亩,已使用"+zbmap.get("YSY_ZJGG")+"亩,剩余"+zbmap.get("SY_ZJGG")+"亩,使用率"+zbmap.get("ZJGG_SYL")+"。"; String zb1="惠州市"+year+"年"+month+"月,已完成组卷的用地报批面积共计"+bpmap.get("TOTAL")+"亩。其中,报批的农用地"+bpmap.get("TOTAL_NYDMJ")+"亩,耕地"+bpmap.get("TOTAL_GDMJ")+"亩,基本农田"+bpmap.get("TOTAL_YJJBNT")+"亩,未利用地"+bpmap.get("TOTAL_WLYD")+"亩。正在报批的面积"+bpmap.get("ZZBP_TOTAL")+"亩,其中:农用地"+bpmap.get("ZZBP_NYDMJ")+"亩,耕地"+bpmap.get("ZZBP_GDMJ")+"亩,基本农田"+bpmap.get("ZZBP_YJJBNT")+"亩,未利用地"+bpmap.get("ZZBP_WLYD")+"亩;已报批面积"+bpmap.get("YBP_TOTAL")+"亩,其中:农用地"+bpmap.get("YBP_NYDMJ")+"亩,耕地"+bpmap.get("YBP_GDMJ")+"亩,基本农田"+bpmap.get("YBP_YJJBNT")+"亩,未利用地"+bpmap.get("YBP_WLYD")+"亩。"; String zb2="惠州市"+year+"年"+month+"月,已完成组卷的用地报批面积共计"+lxmap.get("TOTAL_ZMJ")+"亩。其中,单独选址项目用地报批面积"+lxmap.get("DDXZ_ZMJ")+"亩,去年同期"+lxtbmap.get("DDXZ_ZMJ")+"亩,上月"+lxhbmap.get("DDXZ_ZMJ")+"亩,同比"+tbhb(lxmap.get("DDXZ_ZMJ").toString(),lxtbmap.get("DDXZ_ZMJ").toString())+",环比"+tbhb(lxmap.get("DDXZ_ZMJ").toString(),lxhbmap.get("DDXZ_ZMJ").toString())+";批次用地报批面积"+lxmap.get("CSFP_ZMJ")+"亩,去年同期"+lxtbmap.get("CSFP_ZMJ")+"亩,上月"+lxhbmap.get("CSFP_ZMJ")+"亩,同比"+tbhb(lxmap.get("CSFP_ZMJ").toString(),lxtbmap.get("CSFP_ZMJ").toString())+",环比"+tbhb(lxmap.get("CSFP_ZMJ").toString(),lxhbmap.get("CSFP_ZMJ").toString())+";城市建设用地农用地转用和土地征收实施方案报批面积"+lxmap.get("SSFA_ZMJ")+"亩,去年同期"+lxtbmap.get("SSFA_ZMJ")+"亩,上月"+lxhbmap.get("SSFA_ZMJ")+"亩,同比"+tbhb(lxmap.get("SSFA_ZMJ").toString(),lxtbmap.get("SSFA_ZMJ").toString())+",环比"+tbhb(lxhbmap.get("SSFA_ZMJ").toString(),lxhbmap.get("SSFA_ZMJ").toString())+";“只转不征”项目用地报批面积"+lxmap.get("ZZBP_ZMJ")+"亩,去年同期"+lxtbmap.get("ZZBP_ZMJ")+"亩,上月"+lxhbmap.get("ZZBP_ZMJ")+"亩,同比"+tbhb(lxmap.get("ZZBP_ZMJ").toString(),lxhbmap.get("ZZBP_ZMJ").toString())+",环比"+tbhb(lxmap.get("ZZBP_ZMJ").toString(),lxhbmap.get("ZZBP_ZMJ").toString())+";报国务院批准的城市建设用地(一年一批次)面积"+lxmap.get("GWY_ZMJ")+"亩,去年同期"+lxtbmap.get("GWY_ZMJ")+"亩,上月"+lxhbmap.get("GWY_ZMJ")+"亩,同比"+tbhb(lxmap.get("GWY_ZMJ").toString(),lxtbmap.get("GWY_ZMJ").toString())+",环比"+tbhb(lxmap.get("GWY_ZMJ").toString(),lxhbmap.get("GWY_ZMJ").toString())+"。各区县报批类型统计情况见下表:"; String zb3="惠州市"+year+"年"+month+"月,已完成组卷的用地报批面积共计"+kfmap.get("TOTAL")+"亩,工业用地"+kfmap.get("GF_YD")+"亩,工业用地占比xx%。其中,商服用地报批面积"+kfmap.get("SF_YD")+"亩,去年同期"+kftbmap.get("SF_YD")+"亩,上月"+kfhbmap.get("SF_YD")+"亩,同比"+tbhb(kfmap.get("SF_YD").toString(),kftbmap.get("SF_YD").toString())+",环比"+tbhb(kfmap.get("SF_YD").toString(),kfhbmap.get("SF_YD").toString())+";住宅用地报批面积"+kfmap.get("ZZ_YD")+"亩,去年同期"+kftbmap.get("ZZ_YD")+"亩,上月"+kfhbmap.get("ZZ_YD")+"亩,同比"+tbhb(kfmap.get("ZZ_YD").toString(),kftbmap.get("ZZ_YD").toString())+",环比"+tbhb(kfmap.get("ZZ_YD").toString(),kfhbmap.get("ZZ_YD").toString())+";工矿仓储用地报批面积"+kfmap.get("CC_YD")+"亩,去年同期"+kftbmap.get("CC_YD")+"亩,上月"+kfhbmap.get("CC_YD")+"亩,同比"+tbhb(kfmap.get("CC_YD").toString(),kftbmap.get("CC_YD").toString())+",环比"+tbhb(kfmap.get("CC_YD").toString(),kfhbmap.get("CC_YD").toString())+";其他用地报批面积"+kfmap.get("TOTAL_QTYD")+"亩,去年同期"+kftbmap.get("TOTAL_QTYD")+"亩,上月"+kfhbmap.get("TOTAL_QTYD")+"亩,同比"+tbhb(kfmap.get("TOTAL_QTYD").toString(),kftbmap.get("TOTAL_QTYD").toString())+",环比"+tbhb(kfmap.get("ZZ_YD").toString(),kfhbmap.get("TOTAL_QTYD").toString())+"。各区县开发用途统计情况见下表:"; Document document =new Document(PageSize.A4,50,50,100,20); // 指定页面大小为A4,且自定义页边距(marginLeft、marginRight、marginTop、marginBottom) PdfWriter.getInstance(document, new FileOutputStream(filepath)); document.open(); BaseFont bfChinese; bfChinese=BaseFont.createFont("STSongStd-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);//jar包 Font titielFont = new Font(bfChinese, 22, Font.BOLD);//设置字体 Font dateFont = new Font(bfChinese, 22, Font.NORMAL);//设置字体 Paragraph elements = new Paragraph("惠州市建设项目用地报批评估报告", titielFont); elements.setAlignment(Paragraph.ALIGN_CENTER); document.add(elements); //---------------------------------------------------------------------------- BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.NOT_EMBEDDED); Font size14font = new Font(baseFont,14,Font.NORMAL); //大小为14的正常字体 Font size10font = new Font(baseFont,10); //大小为10的粗体 Paragraph pdate = new Paragraph("(2020年7月)", dateFont); pdate.setAlignment(Paragraph.ALIGN_CENTER); pdate.setSpacingAfter(40f); document.add(pdate); document.add(getP("一、报批情况汇总")); document.add(getPtwo("(一) 指标分配及使用情况")); document.add(getPtwo(zb)); document.add(getPthree("表 1 指标分配及使用情况监控")); PdfPTable pdfPTable=getInitTable(size10font,zblist); document.add(pdfPTable); document.add(getPtwo("(二) 报批情况实时监控")); document.add(getPtwo(zb1)); document.add(getPthree("表 2 用地报批实时统计情况")); pdfPTable=getInitYdBpTable(size10font,bplist); document.add(pdfPTable); //----------------------------------------- document.add(getP("二、报批情况专项统计")); document.add(getPtwo("(一) 按报批类型统计")); document.add(getPtwo(zb2)); document.add(getPthree("表 3 "+year+"年"+month+"月按报批类型统计")); pdfPTable=getInitBplxxqTable(size10font,lxlist); document.add(pdfPTable); document.add(getPthree("表 4 "+year+"年"+month+"月按报批类型同比统计")); pdfPTable=getInitBplxtbTable(size10font,lxlist); document.add(pdfPTable); document.add(getPthree("表 5 "+year+"年"+month+"月按报批类型环比统计")); pdfPTable=getInitBplxhbTable(size10font,lxhblist); document.add(pdfPTable); document.add(getPtwo("(二) 按开发用途统计")); document.add(getPtwo(zb3)); document.add(getPthree("表 6 "+year+"年"+month+"月按开发用途统计")); pdfPTable=getInitkfytxqTable(size10font,kflist); document.add(pdfPTable); document.add(getPthree("表 7 "+year+"年"+month+"月按开发用途同比统计")); pdfPTable=getInitkfyttbTable(size10font,kflist); document.add(pdfPTable); document.add(getPthree("表 8 "+year+"年"+month+"月按开发用途环比统计")); pdfPTable=getInitkfythbTable(size10font,kfhblist); document.add(pdfPTable); document.add(getPfour("惠州市自然资源局")); document.add(getPfour(year+"年"+month+"月")); // 5.关闭文档 document.close(); } private static void setAlignCenter(PdfPCell pdfPCell){ pdfPCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中 pdfPCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); } private static PdfPCell getcell(String text,Font font,int colspan,int rowspan) { PdfPCell c1 = new PdfPCell(new Phrase(text,font)); c1.setColspan(colspan); c1.setRowspan(rowspan); setAlignCenter(c1); // t.addCell(c1); return c1; } private static PdfPCell getcell(String text,Font font) { PdfPCell c1 = new PdfPCell(new Phrase(text,font)); setAlignCenter(c1); return c1; } public static PdfPTable getInitTable(Font font,List<Map<String, Object>> list) throws DocumentException { PdfPTable t = new PdfPTable(16); int width[] = { 50, 50,20,40, 80, 50, 50, 50, 50, 60 }; t.setWidthPercentage(100); PdfPCell c1 = new PdfPCell(new Phrase("指标分配及使用情况监控(公顷)",font)); c1.setColspan(16); c1.setMinimumHeight(20); c1.setRowspan(1); c1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); c1.setBackgroundColor(new BaseColor(61,85,158)); t.addCell(c1); t.setSpacingBefore(10); // t.setWidths(width);
c1 = new PdfPCell(new Phrase("",font)); c1.setRowspan(3); c1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中 c1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);//垂直居中 t.addCell(c1);
t.addCell(getcell("新增建设用地计划指标", font,5,1)); t.addCell(getcell("复垦周转指标", font,5,1)); t.addCell(getcell("增减挂钩指标", font,5,1)); t.addCell(getcell("分配", font,1,2)); t.addCell(getcell("使用", font,2,1)); t.addCell(getcell("剩余", font,1,2)); t.addCell(getcell("使用率", font,1,2)); t.addCell(getcell("分配", font,1,2)); t.addCell(getcell("使用", font,2,1)); t.addCell(getcell("剩余", font,1,2)); t.addCell(getcell("使用率", font,1,2)); t.addCell(getcell("分配", font,1,2)); t.addCell(getcell("使用", font,2,1)); t.addCell(getcell("剩余", font,1,2)); t.addCell(getcell("使用率", font,1,2)); t.addCell(getcell("扣除", font)); t.addCell(getcell("预扣", font)); t.addCell(getcell("扣除", font)); t.addCell(getcell("预扣", font)); t.addCell(getcell("扣除", font)); t.addCell(getcell("预扣", font)); for(Map<String, Object> map:list) { t.addCell(getcell(String.valueOf(map.get("XZQHMC")), font)); t.addCell(getcell(String.valueOf(map.get("XZJSYD")), font)); t.addCell(getcell(String.valueOf(map.get("KC_XZJSYD")), font)); t.addCell(getcell(String.valueOf(map.get("YK_XZJSYD")), font)); t.addCell(getcell(String.valueOf(map.get("SY_XZJSYD")), font)); t.addCell(getcell(String.valueOf(map.get("XZJSYD_SYL")), font)); t.addCell(getcell(String.valueOf(map.get("CJFK")), font)); t.addCell(getcell(String.valueOf(map.get("KC_CJFK")), font)); t.addCell(getcell(String.valueOf(map.get("YK_CJFK")), font)); t.addCell(getcell(String.valueOf(map.get("SY_CJFK")), font)); t.addCell(getcell(String.valueOf(map.get("CJFK_SYL")), font)); t.addCell(getcell(String.valueOf(map.get("ZJGG")), font)); t.addCell(getcell(String.valueOf(map.get("KC_ZJGG")), font)); t.addCell(getcell(String.valueOf(map.get("YK_ZJGG")), font)); t.addCell(getcell(String.valueOf(map.get("SY_ZJGG")), font)); t.addCell(getcell(String.valueOf(map.get("ZJGG_SYL")), font)); }
return t; } /** * 用地报批表格 * @param font * @param list * @return * @throws DocumentException */ public static PdfPTable getInitYdBpTable(Font font,List<Map<String, Object>> list) throws DocumentException { PdfPTable t = new PdfPTable(16); int width[] = { 50, 50,20,40, 80, 50, 50, 50, 50, 60 }; t.setWidthPercentage(100); PdfPCell c1 = new PdfPCell(new Phrase("用地报批实时监控(公顷)",font)); c1.setColspan(16); c1.setMinimumHeight(20); c1.setRowspan(1); c1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); c1.setBackgroundColor(new BaseColor(61,85,158)); t.addCell(c1); t.setSpacingBefore(10); // t.setWidths(width);
c1 = new PdfPCell(new Phrase("",font)); c1.setRowspan(2); c1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中 c1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);//垂直居中 t.addCell(c1);
t.addCell(getcell("农用地", font,3,1)); t.addCell(getcell("其中耕地", font,3,1)); t.addCell(getcell("其中基本农田", font,3,1)); t.addCell(getcell("未利用地", font,3,1)); t.addCell(getcell("合计", font,3,1)); t.addCell(getcell("在办", font,1,1)); t.addCell(getcell("批复", font,1,1)); t.addCell(getcell("小计", font,1,1)); t.addCell(getcell("在办", font,1,1)); t.addCell(getcell("批复", font,1,1)); t.addCell(getcell("小计", font,1,1)); t.addCell(getcell("在办", font,1,1)); t.addCell(getcell("批复", font,1,1)); t.addCell(getcell("小计", font,1,1)); t.addCell(getcell("在办", font,1,1)); t.addCell(getcell("批复", font,1,1)); t.addCell(getcell("小计", font,1,1)); t.addCell(getcell("在办", font,1,1)); t.addCell(getcell("批复", font,1,1)); t.addCell(getcell("小计", font,1,1)); for(Map<String, Object> map:list) { t.addCell(getcell(String.valueOf(map.get("XZQHMC")), font)); t.addCell(getcell(String.valueOf(map.get("ZZBP_NYDMJ")), font)); t.addCell(getcell(String.valueOf(map.get("YBP_NYDMJ")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL_NYDMJ")), font)); t.addCell(getcell(String.valueOf(map.get("ZZBP_GDMJ")), font)); t.addCell(getcell(String.valueOf(map.get("YBP_GDMJ")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL_GDMJ")), font)); t.addCell(getcell(String.valueOf(map.get("ZZBP_YJJBNT")), font)); t.addCell(getcell(String.valueOf(map.get("YBP_YJJBNT")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL_YJJBNT")), font)); t.addCell(getcell(String.valueOf(map.get("ZZBP_WLYD")), font)); t.addCell(getcell(String.valueOf(map.get("YBP_WLYD")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL_WLYD")), font)); t.addCell(getcell(String.valueOf(map.get("ZZBP_TOTAL")), font)); t.addCell(getcell(String.valueOf(map.get("YBP_TOTAL")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL")), font)); }
return t; } /** * 报批类型-现期 * @param font * @param list * @return * @throws DocumentException */ public static PdfPTable getInitBplxxqTable(Font font,List<Map<String, Object>> list) throws DocumentException { PdfPTable t = new PdfPTable(6); int width[] = { 50, 50,20,40, 80, 50, 50, 50, 50, 60 }; t.setWidthPercentage(100); PdfPCell c1 = new PdfPCell(new Phrase("用地报批类型监测(公顷)",font)); c1.setColspan(6); c1.setMinimumHeight(20); c1.setRowspan(1); c1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); c1.setBackgroundColor(new BaseColor(61,85,158)); t.addCell(c1); t.setSpacingBefore(10); // t.setWidths(width);
c1 = new PdfPCell(new Phrase("",font)); c1.setRowspan(1); c1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中 c1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);//垂直居中 t.addCell(c1);
t.addCell(getcell("单独选址项目用地报批", font,1,1)); t.addCell(getcell("批次用地报批", font,1,1)); t.addCell(getcell("“只转不征”项目用地报批", font,1,1)); t.addCell(getcell("报国务院批准的城市建设用地(一年一批次)", font,1,1)); t.addCell(getcell("合计", font,1,1)); for(Map<String, Object> map:list) { if("现期".equals(map.get("TYPE"))) { t.addCell(getcell(String.valueOf(map.get("XZQHMC")), font)); t.addCell(getcell(String.valueOf(map.get("DDXZ_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("CSFP_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("ZZBP_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("GWY_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL_ZMJ")), font)); } }
return t; } /** * 报批类型-同比 * @param font * @param list * @return * @throws DocumentException */ public static PdfPTable getInitBplxtbTable(Font font,List<Map<String, Object>> list) throws DocumentException { PdfPTable t = new PdfPTable(7); int width[] = { 50, 50,20,40, 80, 50, 50, 50, 50, 60 }; t.setWidthPercentage(100); PdfPCell c1 = new PdfPCell(new Phrase("用地报批类型监测(公顷)",font)); c1.setColspan(7); c1.setMinimumHeight(20); c1.setRowspan(1); c1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); c1.setBackgroundColor(new BaseColor(61,85,158)); t.addCell(c1); t.setSpacingBefore(10); // t.setWidths(width);
c1 = new PdfPCell(new Phrase("",font)); c1.setRowspan(1); c1.setColspan(2); c1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中 c1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);//垂直居中 t.addCell(c1);
t.addCell(getcell("单独选址项目用地报批", font,1,1)); t.addCell(getcell("批次用地报批", font,1,1)); t.addCell(getcell("“只转不征”项目用地报批", font,1,1)); t.addCell(getcell("报国务院批准的城市建设用地(一年一批次)", font,1,1)); t.addCell(getcell("合计", font,1,1)); Map<String,List<Map<String, Object>>> maps=list.stream().collect(Collectors.groupingBy(m->String.valueOf(m.get("XZQHMC")))); for(String key:maps.keySet()) { t.addCell(getcell(key, font,1,2)); List<Map<String, Object>> list2=maps.get(key); for(Map<String, Object> map:list2) { if("现期".equals(map.get("TYPE"))) { t.addCell(getcell("现期", font)); t.addCell(getcell(String.valueOf(map.get("DDXZ_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("CSFP_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("ZZBP_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("GWY_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL_ZMJ")), font)); } if("同比".equals(map.get("TYPE"))) { // t.addCell(getcell(String.valueOf(map.get("XZQHMC")), font)); t.addCell(getcell("同比", font)); t.addCell(getcell(String.valueOf(map.get("DDXZ_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("CSFP_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("ZZBP_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("GWY_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL_ZMJ")), font)); } } } return t; } /** * 报批类型环比 * @param font * @param list * @return * @throws DocumentException */ public static PdfPTable getInitBplxhbTable(Font font,List<Map<String, Object>> list) throws DocumentException { PdfPTable t = new PdfPTable(7); int width[] = { 50, 50,20,40, 80, 50, 50, 50, 50, 60 }; t.setWidthPercentage(100); PdfPCell c1 = new PdfPCell(new Phrase("用地报批类型监测(公顷)",font)); c1.setColspan(7); c1.setMinimumHeight(20); c1.setRowspan(1); c1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); c1.setBackgroundColor(new BaseColor(61,85,158)); t.addCell(c1); t.setSpacingBefore(10); // t.setWidths(width);
c1 = new PdfPCell(new Phrase("",font)); c1.setRowspan(1); c1.setColspan(2); c1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中 c1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);//垂直居中 t.addCell(c1);
t.addCell(getcell("单独选址项目用地报批", font,1,1)); t.addCell(getcell("批次用地报批", font,1,1)); t.addCell(getcell("“只转不征”项目用地报批", font,1,1)); t.addCell(getcell("报国务院批准的城市建设用地(一年一批次)", font,1,1)); t.addCell(getcell("合计", font,1,1)); Map<String,List<Map<String, Object>>> maps=list.stream().collect(Collectors.groupingBy(m->String.valueOf(m.get("XZQHMC")))); for(String key:maps.keySet()) { t.addCell(getcell(key, font,1,2)); List<Map<String, Object>> list2=maps.get(key); for(Map<String, Object> map:list2) { if("现期".equals(map.get("TYPE"))) { t.addCell(getcell("现期", font)); t.addCell(getcell(String.valueOf(map.get("DDXZ_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("CSFP_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("ZZBP_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("GWY_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL_ZMJ")), font)); } if("环比".equals(map.get("TYPE"))) { // t.addCell(getcell(String.valueOf(map.get("XZQHMC")), font)); t.addCell(getcell("环比", font)); t.addCell(getcell(String.valueOf(map.get("DDXZ_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("CSFP_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("ZZBP_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("GWY_ZMJ")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL_ZMJ")), font)); } } } return t; } /** * 开发用途-现期 * @param font * @param list * @return * @throws DocumentException */ public static PdfPTable getInitkfytxqTable(Font font,List<Map<String, Object>> list) throws DocumentException { PdfPTable t = new PdfPTable(13); int width[] = { 50, 50,20,40, 80, 50, 50, 50, 50, 60 }; t.setWidthPercentage(100); PdfPCell c1 = new PdfPCell(new Phrase("用地报批开发用途监控(公顷)",font)); c1.setColspan(13); c1.setMinimumHeight(20); c1.setRowspan(1); c1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); c1.setBackgroundColor(new BaseColor(61,85,158)); t.addCell(c1); t.setSpacingBefore(10); // t.setWidths(width);
c1 = new PdfPCell(new Phrase("",font)); c1.setRowspan(2); c1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中 c1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);//垂直居中 t.addCell(c1);
t.addCell(getcell("商服用地", font,1,2)); t.addCell(getcell("住宅用地", font,1,2)); t.addCell(getcell("工矿仓储用地", font,4,1)); t.addCell(getcell("其它用地", font,5,1)); t.addCell(getcell("合计", font,1,1)); t.addCell(getcell("工业用地", font,1,1)); t.addCell(getcell("仓储用地", font,1,1)); t.addCell(getcell("盐田", font,1,1)); t.addCell(getcell("采矿", font,1,1)); t.addCell(getcell("公服用地", font,1,1)); t.addCell(getcell("特殊用地", font,1,1)); t.addCell(getcell("交通运输用地", font,1,1)); t.addCell(getcell("水利设施用地", font,1,1)); t.addCell(getcell("其它", font,1,1)); t.addCell(getcell("", font,1,1)); for(Map<String, Object> map:list) { if("现期".equals(map.get("TYPE"))) { t.addCell(getcell(String.valueOf(map.get("XZQHMC")), font)); t.addCell(getcell(String.valueOf(map.get("SF_YD")), font)); t.addCell(getcell(String.valueOf(map.get("ZZ_YD")), font)); t.addCell(getcell(String.valueOf(map.get("GY_YD")), font)); t.addCell(getcell(String.valueOf(map.get("CC_YD")), font)); t.addCell(getcell(String.valueOf(map.get("YT")), font)); t.addCell(getcell(String.valueOf(map.get("CK")), font)); t.addCell(getcell(String.valueOf(map.get("GF_YD")), font)); t.addCell(getcell(String.valueOf(map.get("TS_YD")), font)); t.addCell(getcell(String.valueOf(map.get("JTYS_YD")), font)); t.addCell(getcell(String.valueOf(map.get("SL")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL_QTYD")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL")), font)); } }
return t; } /** * 开发用途-同比 * @param font * @param list * @return * @throws DocumentException */ public static PdfPTable getInitkfyttbTable(Font font,List<Map<String, Object>> list) throws DocumentException { PdfPTable t = new PdfPTable(14); int width[] = { 50, 50,20,40, 80, 50, 50, 50, 50, 60 }; t.setWidthPercentage(100); PdfPCell c1 = new PdfPCell(new Phrase("用地报批开发用途监控(公顷)",font)); c1.setColspan(14); c1.setMinimumHeight(20); c1.setRowspan(1); c1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); c1.setBackgroundColor(new BaseColor(61,85,158)); t.addCell(c1); t.setSpacingBefore(10); // t.setWidths(width);
c1 = new PdfPCell(new Phrase("",font)); c1.setRowspan(2); c1.setColspan(2); c1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中 c1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);//垂直居中 t.addCell(c1);
t.addCell(getcell("商服用地", font,1,2)); t.addCell(getcell("住宅用地", font,1,2)); t.addCell(getcell("工矿仓储用地", font,4,1)); t.addCell(getcell("其它用地", font,5,1)); t.addCell(getcell("合计", font,1,1)); t.addCell(getcell("工业用地", font,1,1)); t.addCell(getcell("仓储用地", font,1,1)); t.addCell(getcell("盐田", font,1,1)); t.addCell(getcell("采矿", font,1,1)); t.addCell(getcell("公服用地", font,1,1)); t.addCell(getcell("特殊用地", font,1,1)); t.addCell(getcell("交通运输用地", font,1,1)); t.addCell(getcell("水利设施用地", font,1,1)); t.addCell(getcell("其它", font,1,1)); t.addCell(getcell("", font,1,1)); Map<String,List<Map<String, Object>>> maps=list.stream().collect(Collectors.groupingBy(m->String.valueOf(m.get("XZQHMC")))); for(String key:maps.keySet()) { t.addCell(getcell(key, font,1,2)); List<Map<String, Object>> list2=maps.get(key); for(Map<String, Object> map:list2) { if("现期".equals(map.get("TYPE"))) { t.addCell(getcell("现期", font)); t.addCell(getcell(String.valueOf(map.get("SF_YD")), font)); t.addCell(getcell(String.valueOf(map.get("ZZ_YD")), font)); t.addCell(getcell(String.valueOf(map.get("GY_YD")), font)); t.addCell(getcell(String.valueOf(map.get("CC_YD")), font)); t.addCell(getcell(String.valueOf(map.get("YT")), font)); t.addCell(getcell(String.valueOf(map.get("CK")), font)); t.addCell(getcell(String.valueOf(map.get("GF_YD")), font)); t.addCell(getcell(String.valueOf(map.get("TS_YD")), font)); t.addCell(getcell(String.valueOf(map.get("JTYS_YD")), font)); t.addCell(getcell(String.valueOf(map.get("SL")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL_QTYD")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL")), font)); } if("同比".equals(map.get("TYPE"))) { // t.addCell(getcell(String.valueOf(map.get("XZQHMC")), font)); t.addCell(getcell("同比", font)); t.addCell(getcell(String.valueOf(map.get("SF_YD")), font)); t.addCell(getcell(String.valueOf(map.get("ZZ_YD")), font)); t.addCell(getcell(String.valueOf(map.get("GY_YD")), font)); t.addCell(getcell(String.valueOf(map.get("CC_YD")), font)); t.addCell(getcell(String.valueOf(map.get("YT")), font)); t.addCell(getcell(String.valueOf(map.get("CK")), font)); t.addCell(getcell(String.valueOf(map.get("GF_YD")), font)); t.addCell(getcell(String.valueOf(map.get("TS_YD")), font)); t.addCell(getcell(String.valueOf(map.get("JTYS_YD")), font)); t.addCell(getcell(String.valueOf(map.get("SL")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL_QTYD")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL")), font)); } } } return t; } /** * 开发用途环比 * @param font * @param list * @return * @throws DocumentException */ public static PdfPTable getInitkfythbTable(Font font,List<Map<String, Object>> list) throws DocumentException { PdfPTable t = new PdfPTable(14); int width[] = { 50, 50,20,40, 80, 50, 50, 50, 50, 60 }; t.setWidthPercentage(100); PdfPCell c1 = new PdfPCell(new Phrase("用地报批开发用途监控(公顷)",font)); c1.setColspan(14); c1.setMinimumHeight(20); c1.setRowspan(1); c1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); c1.setBackgroundColor(new BaseColor(61,85,158)); t.addCell(c1); t.setSpacingBefore(10); // t.setWidths(width);
c1 = new PdfPCell(new Phrase("",font)); c1.setRowspan(2); c1.setColspan(2); c1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中 c1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);//垂直居中 t.addCell(c1);
t.addCell(getcell("商服用地", font,1,2)); t.addCell(getcell("住宅用地", font,1,2)); t.addCell(getcell("工矿仓储用地", font,4,1)); t.addCell(getcell("其它用地", font,5,1)); t.addCell(getcell("合计", font,1,1)); t.addCell(getcell("工业用地", font,1,1)); t.addCell(getcell("仓储用地", font,1,1)); t.addCell(getcell("盐田", font,1,1)); t.addCell(getcell("采矿", font,1,1)); t.addCell(getcell("公服用地", font,1,1)); t.addCell(getcell("特殊用地", font,1,1)); t.addCell(getcell("交通运输用地", font,1,1)); t.addCell(getcell("水利设施用地", font,1,1)); t.addCell(getcell("其它", font,1,1)); t.addCell(getcell("", font,1,1)); Map<String,List<Map<String, Object>>> maps=list.stream().collect(Collectors.groupingBy(m->String.valueOf(m.get("XZQHMC")))); for(String key:maps.keySet()) { t.addCell(getcell(key, font,1,2)); List<Map<String, Object>> list2=maps.get(key); for(Map<String, Object> map:list2) { if("现期".equals(map.get("TYPE"))) { t.addCell(getcell("现期", font)); t.addCell(getcell(String.valueOf(map.get("SF_YD")), font)); t.addCell(getcell(String.valueOf(map.get("ZZ_YD")), font)); t.addCell(getcell(String.valueOf(map.get("GY_YD")), font)); t.addCell(getcell(String.valueOf(map.get("CC_YD")), font)); t.addCell(getcell(String.valueOf(map.get("YT")), font)); t.addCell(getcell(String.valueOf(map.get("CK")), font)); t.addCell(getcell(String.valueOf(map.get("GF_YD")), font)); t.addCell(getcell(String.valueOf(map.get("TS_YD")), font)); t.addCell(getcell(String.valueOf(map.get("JTYS_YD")), font)); t.addCell(getcell(String.valueOf(map.get("SL")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL_QTYD")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL")), font)); } if("环比".equals(map.get("TYPE"))) { // t.addCell(getcell(String.valueOf(map.get("XZQHMC")), font)); t.addCell(getcell("环比", font)); t.addCell(getcell(String.valueOf(map.get("SF_YD")), font)); t.addCell(getcell(String.valueOf(map.get("ZZ_YD")), font)); t.addCell(getcell(String.valueOf(map.get("GY_YD")), font)); t.addCell(getcell(String.valueOf(map.get("CC_YD")), font)); t.addCell(getcell(String.valueOf(map.get("YT")), font)); t.addCell(getcell(String.valueOf(map.get("CK")), font)); t.addCell(getcell(String.valueOf(map.get("GF_YD")), font)); t.addCell(getcell(String.valueOf(map.get("TS_YD")), font)); t.addCell(getcell(String.valueOf(map.get("JTYS_YD")), font)); t.addCell(getcell(String.valueOf(map.get("SL")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL_QTYD")), font)); t.addCell(getcell(String.valueOf(map.get("TOTAL")), font)); } } } return t; } public static void table(Document document) throws DocumentException, IOException { //创建字体 BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.NOT_EMBEDDED); Font size14font = new Font(baseFont,14,Font.NORMAL); //大小为14的正常字体 Font size10font = new Font(baseFont,10,Font.BOLD); //大小为10的粗体 //添加标题 /*PdfPTable tableName = new PdfPTable(1); tableName.setSpacingBefore(25); // tableName.setSpacingAfter(25); tableName.setWidthPercentage(90); //设置标题长度占纸张比例 tableName.addCell(mircoSoftFont("个人信息",size14font,50,true,true)); document.add(tableName); //添加第二行的数据 PdfPTable secondRowTable = new PdfPTable(3); //三列的意思 secondRowTable.setWidthPercentage(90); //这里的数组长度是上面创建的列数,数组的总和为1,就是按比例划分的意思 secondRowTable.setTotalWidth(new float[]{0.18f,0.32f,0.5f}); secondRowTable.addCell(mircoSoftFont(" 姓名: ",size10font,50,false,true)); secondRowTable.addCell(mircoSoftFont("李晓明",size10font,50,false,true)); secondRowTable.addCell(mircoSoftFont(" 出生日期: 1994年3月14日",size10font,50,false,true)); document.add(secondRowTable); //第三行数据 PdfPTable thirdRowTable = new PdfPTable(3); thirdRowTable.setWidthPercentage(90); thirdRowTable.setTotalWidth(new float[]{0.18f,0.32f,0.5f}); thirdRowTable.addCell(mircoSoftFont(" 名族:",size10font,50,false,true)); thirdRowTable.addCell(mircoSoftFont("汉族",size10font,50,false,true)); thirdRowTable.addCell(mircoSoftFont(" 联系电话: 13888880000",size10font,50,false,true)); document.add(thirdRowTable); //第四行数据 PdfPTable fourthRowTable = new PdfPTable(2); fourthRowTable.setWidthPercentage(90); fourthRowTable.setTotalWidth(new float[]{0.66f,0.34f}); fourthRowTable.addCell(mircoSoftFont(" 个人描述 :",size10font,175,false,false)); fourthRowTable.addCell(mircoSoftFont("个人特长 :",size10font,175,false,false)); document.add(fourthRowTable); //第五行 PdfPTable fifthDetailName = new PdfPTable(1); fifthDetailName.setWidthPercentage(90); fifthDetailName.addCell(mircoSoftFont("获奖记录 :",size14font,50,true,true)); document.add(fifthDetailName); //第六行 PdfPTable sisthRowTalbe= new PdfPTable(1); sisthRowTalbe.setWidthPercentage(90); sisthRowTalbe.addCell(mircoSoftFont(" 联系地址: "+"广东省广州市天河区XXXXXXXXXXXXXXXXXX",size10font,50,false,true)); document.add(sisthRowTalbe);*/ PdfPTable seventhRowTalbe = new PdfPTable(1); seventhRowTalbe.setWidthPercentage(90); seventhRowTalbe.addCell(mircoSoftFont(" 指标分配及使用情况监控 ",size14font,20,false,true,true)); seventhRowTalbe.setSpacingBefore(25); document.add(seventhRowTalbe); //第八行 PdfPTable eiththRowTalbe = new PdfPTable(3); eiththRowTalbe.setWidthPercentage(90); eiththRowTalbe.setTotalWidth(new float[]{0.3f,0.5f,0.2f}); eiththRowTalbe.addCell(mircoSoftFont(" 分配指标",size10font,20,true,true,false)); eiththRowTalbe.addCell(mircoSoftFont(" 就读日期",size10font,20,true,true,false)); eiththRowTalbe.addCell(mircoSoftFont(" 联系人",size10font,20,true,true,false)); document.add(eiththRowTalbe); //接下来加List String school = "XXX学校"; String time = "201909 - 2022-06"; String name = "陈某"; for (int i = 0 ;i<4 ;i++){ PdfPTable tempTable = new PdfPTable(3); tempTable.setWidthPercentage(90); tempTable.setTotalWidth(new float[]{0.3f,0.5f,0.2f}); tempTable.addCell(mircoSoftFont(school,size10font,20,true,true,false)); tempTable.addCell(mircoSoftFont(time,size10font,20,true,true,false)); tempTable.addCell(mircoSoftFont(name,size10font,20,true,true,false)); document.add(tempTable); }
} private static PdfPCell mircoSoftFont(String str,Font font,int high,boolean alignCenter,boolean alignMidde,Boolean alignLeft){ PdfPCell pdfPCell = new PdfPCell(new Phrase(str,font)); pdfPCell.setMinimumHeight(high); pdfPCell.setUseAscender(true); // 设置可以居中 if (alignCenter){ pdfPCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中 } if(alignLeft) { pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT); } if (alignMidde){ pdfPCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中 } return pdfPCell; }
private static PdfPCell mircoSoftFont(String str,Font font,int high,boolean alignCenter,boolean alignMidde,Boolean alignLeft,boolean haveColor){ PdfPCell pdfPCell = new PdfPCell(new Phrase(str,font)); pdfPCell.setMinimumHeight(high); pdfPCell.setUseAscender(true); // 设置可以居中 if (alignCenter){ pdfPCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中 } if(alignLeft) { pdfPCell.setHorizontalAlignment(pdfPCell.ALIGN_LEFT); } if (alignMidde){ pdfPCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中 } if (haveColor){ //颜色代码 RGB pdfPCell.setBackgroundColor(new BaseColor(217,217,217)); } return pdfPCell; } public static PdfPTable t() { PdfPTable t = new PdfPTable(3); t.setSpacingBefore(25); t.setSpacingAfter(25); PdfPCell c1 = new PdfPCell(new Phrase("Header1")); t.addCell(c1); PdfPCell c2 = new PdfPCell(new Phrase("Header2")); t.addCell(c2); PdfPCell c3 = new PdfPCell(new Phrase("Header3")); t.addCell(c3); t.addCell("1.1"); t.addCell("1.2"); t.addCell("1.3"); // section1.add(t); return t; } private static PdfPTable createTable(int colNum, float[] columnWidths) { PdfPTable table = new PdfPTable(colNum); try { table.setWidths(columnWidths); } catch (DocumentException e) { e.printStackTrace(); } table.setSpacingBefore(20f);//设置页边距 table.setWidthPercentage(100);//设置表格宽度为100% return table; } private static void generatorHeader(PdfPTable table, String headerSuffix) throws DocumentException, IOException {
table.addCell(createPdfPCell("Location 0BBPW", 1, 1, Element.ALIGN_CENTER)); table.addCell(createPdfPCell("哈哈哈", 2, 2, Element.ALIGN_CENTER));
} private static PdfPCell createPdfPCell(String text, int colSpan, int rowSpan) throws DocumentException, IOException { return createPdfPCell(text, colSpan, rowSpan, Element.ALIGN_RIGHT); }
private static PdfPCell createPdfPCell(String text, int colSpan, int rowSpan, int align) throws DocumentException, IOException { PdfPCell pdfPCell = new PdfPCell(); pdfPCell.setColspan(colSpan); pdfPCell.setRowspan(rowSpan); pdfPCell.setPhrase(createParagraph(text)); pdfPCell.setHorizontalAlignment(align); pdfPCell.setVerticalAlignment(Element.ALIGN_MIDDLE); return pdfPCell; }
private static Paragraph createParagraph(String text) throws DocumentException, IOException { Paragraph paragraph; BaseFont bfChinese; bfChinese=BaseFont.createFont("STSongStd-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);//jar包 Font font = new Font(bfChinese, 8, Font.NORMAL); paragraph = new Paragraph(text, font); paragraph.setAlignment(Phrase.ALIGN_CENTER); return paragraph; } public static String tbhb(String val,String val1) { double val2=Double.parseDouble(val); double val3=Double.parseDouble(val1); double res=0; if(val3!=0) { res=Utils.decimalFormat((val2-val3)/val3*100, 2); } if(res>=0) { return "增加"+res+"%"; }else { return "减少"+res+"%"; } } private static Paragraph getP(String name) throws DocumentException, IOException { BaseFont bfChinese=BaseFont.createFont("STSongStd-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);//jar包 Font bigtitielFont = new Font(bfChinese, 18, Font.BOLD);//设置字体 Paragraph p=new Paragraph(name,bigtitielFont);//设置字体样式 p.setAlignment(3);//设置文字居中 0靠左 1,居中 2,靠右 p.setFirstLineIndent(24);// 首行缩进 p.setLeading(35f); //行间距 return p; } private static Paragraph getPtwo(String name) throws DocumentException, IOException { BaseFont bfChinese=BaseFont.createFont("STSongStd-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);//jar包 Font FontChinese = new Font(bfChinese, 16, Font.NORMAL); Paragraph p2=new Paragraph(name,FontChinese);//设置字体样式 p2.setAlignment(3);//设置文字居中 0靠左 1,居中 2,靠右 p2.setFirstLineIndent(24);// 首行缩进 p2.setLeading(35f); //行间距 return p2; } private static Paragraph getPthree(String name) throws DocumentException, IOException { BaseFont bfChinese=BaseFont.createFont("STSongStd-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);//jar包 Font FontChinese = new Font(bfChinese, 10, Font.NORMAL); Paragraph p2=new Paragraph(name,FontChinese);//设置字体样式 p2.setAlignment(1);//设置文字居中 0靠左 1,居中 2,靠右 // p2.setFirstLineIndent(24);// 首行缩进 p2.setLeading(35f); //行间距 return p2; } private static Paragraph getPfour(String name) throws DocumentException, IOException { BaseFont bfChinese=BaseFont.createFont("STSongStd-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);//jar包 Font FontChinese = new Font(bfChinese, 16, Font.NORMAL); Paragraph p2=new Paragraph(name,FontChinese);//设置字体样式 p2.setAlignment(2);//设置文字居中 0靠左 1,居中 2,靠右 // p2.setFirstLineIndent(24);// 首行缩进 p2.setLeading(35f); //行间距 return p2; }
public static void main(String[] args) throws Exception { // generatePdf("2020"); }
}