生成合同

This commit is contained in:
1073413548 2024-08-09 16:43:11 +08:00
parent 6121032236
commit 3760c669ff

View File

@ -1,5 +1,6 @@
package com.pusong.common.doc.util;
import com.alibaba.fastjson.JSON;
import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.tool.xml.XMLWorkerHelper;
@ -23,30 +24,32 @@ public class PdfGenerator {
public static void main(String[] args) throws Exception {
// 创建数据模型
Map<String, Object> data = new HashMap<>();
data.put("text1", "天津浦颂企业管理咨询有限公司");
data.put("text2", "");
data.put("total", 1000);
List<Map<String,String>> map = new ArrayList<>();
Map<String,String> map1=new HashMap<>();
map1.put("id","7894564123");
map.add(map1);
Map<String,String> map2 =new HashMap<>();
map2.put("id","7894564123");
map.add(map2);
data.put("items",map);
// 设置模板目录
Configuration configuration = new Configuration(Configuration.VERSION_2_3_31);
configuration.setDirectoryForTemplateLoading(new File(System.getProperty("user.dir")+"\\doc"));
// 加载模板
Template template = configuration.getTemplate("report.ftl");
data.put("imagePath",System.getProperty("user.dir"));
// 生成HTML
String html = processTemplate(template, data);
// 生成PDF
generatePdf(html, "D:/王立帅/临时/output.pdf");
// // 创建数据模型
// Map<String, Object> data = new HashMap<>();
// data.put("text1", "天津浦颂企业管理咨询有限公司");
// data.put("text2", "");
// data.put("total", 1000);
// List<Map<String,String>> map = new ArrayList<>();
// Map<String,String> map1=new HashMap<>();
// map1.put("id","7894564123");
// map.add(map1);
// Map<String,String> map2 =new HashMap<>();
// map2.put("id","7894564123");
// map.add(map2);
// data.put("items",map);
//
// // 设置模板目录
// Configuration configuration = new Configuration(Configuration.VERSION_2_3_31);
// configuration.setDirectoryForTemplateLoading(new File(System.getProperty("user.dir")+"\\doc"));
// // 加载模板
// Template template = configuration.getTemplate("report.ftl");
// data.put("imagePath",System.getProperty("user.dir"));
// // 生成HTML
// String html = processTemplate(template, data);
// // 生成PDF
// generatePdf(html, "D:/王立帅/临时/output.pdf");
String str = " - {\"business\":[{\"businessAmount\":500,\"businessType\":\"1\",\"contractCode\":\"\",\"detailBos\":[{\"amount\":100,\"amountDesc\":\"备注\",\"businessProject\":\"1\",\"businessProjectLabel\":\"测试1\",\"contractCode\":\"\",\"id\":0}],\"id\":0}],\"contract\":{\"applyDate\":1722355200000,\"companyId\":0,\"contractAmount\":500,\"contractCode\":\"\",\"contractMain\":\"1\",\"contractName\":\"合同名称\",\"customId\":1816388144534081538,\"customManager\":1,\"customScene\":\"\",\"isProxy\":\"\",\"params\":{},\"payModeDesc\":\"支付方式\",\"signDesc\":\"描述描述\"},\"company\":{\"companyAccountBank\":\"银行编码\",\"companyAccountBankAdress\":\"开户行地址\",\"companyAdress\":\"公司地址\",\"companyName\":\"公司名\",\"customId\":0,\"id\":0,\"legalPersonIdcard\":\"法人身份证\",\"legalPersonName\":\"法人姓名\",\"legalPersonPhone\":\"法人手机号\"},\"customer\":{\"black\":\"0\",\"createBy\":1,\"createDept\":103,\"createTime\":1721895655000,\"customLevel\":\"2\",\"customManager\":3,\"customMobile\":\"13511245332\",\"customName\":\"东洲\",\"customSource\":\"抖音\",\"customStatus\":\"1\",\"delFlag\":0,\"id\":1816388144534081538,\"params\":{},\"tenantId\":\"000000\",\"updateBy\":1,\"updateTime\":1723097358000}}";
makePdf(JSON.parseObject(str,Map.class),"D:/王立帅/临时/output.pdf","report.ftl");
}
@ -61,7 +64,7 @@ public class PdfGenerator {
// 生成HTML
String html = processTemplate(template, data);
// 生成PDF
generatePdf(html, "D:/王立帅/临时/output.pdf");
// generatePdf(html, "D:/王立帅/临时/output.pdf");
generatePdf(html, pdfpath);
}
private static String processTemplate(Template template, Map<String, Object> data) throws IOException, TemplateException {