pdf 预览
This commit is contained in:
parent
198008366e
commit
bc5136ebbb
@ -11,16 +11,17 @@ import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.system.fantang.common.NumberToList;
|
||||
import com.ruoyi.system.fantang.domain.FtPrepaymentDao;
|
||||
import com.ruoyi.system.fantang.domain.FtPrepaymentVo;
|
||||
import com.ruoyi.system.fantang.service.IFtPrepaymentDaoService;
|
||||
import com.ruoyi.system.fantang.utils.PdfUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.poi.ss.formula.functions.EDate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -182,22 +183,20 @@ public class FtPrepaymentDaoController extends BaseController {
|
||||
|
||||
@PostMapping("/generateReceiptPdf")
|
||||
public AjaxResult generateReceiptPdf(@RequestBody JSONObject params) {
|
||||
Map<String, String> convert = NumberToList.convertTo(123.12F, "1");
|
||||
System.out.println(convert);
|
||||
// Map<String, String> convert = NumberToList.convertTo(123.12F, "1");
|
||||
// System.out.println(convert);
|
||||
|
||||
System.out.println(params);
|
||||
|
||||
// 模板路径
|
||||
String templatePath = "F:\\pdfTemplate\\饭堂票据模板.pdf";
|
||||
String templatePath = "F:\\pdfTemplate\\饭堂票据模板2.pdf";
|
||||
|
||||
System.out.println(RuoYiConfig.getUploadPath());
|
||||
|
||||
// 生成的新文件路径
|
||||
String outputPath = RuoYiConfig.getUploadPath() + "\\饭堂票据.pdf";
|
||||
|
||||
// 数据
|
||||
Map<String, Object> values = new HashMap<>();
|
||||
|
||||
// 填入模板
|
||||
PdfUtils.fillTemplate(templatePath, outputPath, values);
|
||||
PdfUtils.generatePrepaymentPdf(templatePath, outputPath, params);
|
||||
|
||||
// 下载地址
|
||||
String downloadPath = "profile/upload/饭堂票据.pdf";
|
||||
|
@ -1,12 +1,15 @@
|
||||
package com.ruoyi.system.fantang.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.itextpdf.text.Document;
|
||||
import com.itextpdf.text.DocumentException;
|
||||
import com.itextpdf.text.pdf.*;
|
||||
import com.ruoyi.system.fantang.common.NumberToList;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@ -14,7 +17,7 @@ import java.util.Map;
|
||||
|
||||
public class PdfUtils {
|
||||
|
||||
public static void fillTemplate(String templatePath, String outputPath, Map<String, Object> values) {
|
||||
public static void fillTemplate(String templatePath, String outputPath, Map<String, String> values) {
|
||||
|
||||
PdfReader reader;
|
||||
FileOutputStream out;
|
||||
@ -30,35 +33,34 @@ public class PdfUtils {
|
||||
BaseFont baseFont = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
|
||||
form.addSubstitutionFont(baseFont);
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("departName", "杜阮颐养院");
|
||||
map.put("payUnit", "苏镜泉");
|
||||
map.put("hospitalId", "R20081001");
|
||||
Date date = new Date();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
||||
map.put("invoiceDate", sdf.format(date));
|
||||
map.put("projName1", "预付款 2020.10.06 至 2021.02.01");
|
||||
map.put("oneQian1", "1");
|
||||
map.put("oneBai1", "1");
|
||||
map.put("oneShi1", "1");
|
||||
map.put("oneWan", "1");
|
||||
map.put("oneQian2", "1");
|
||||
map.put("oneBai2", "1");
|
||||
map.put("oneShi2", "1");
|
||||
map.put("oneYuan", "1");
|
||||
map.put("oneJiao", "1");
|
||||
map.put("oneFen", "1");
|
||||
map.put("priceLite", "¥11111111.11");
|
||||
map.put("priceBig", "壹仟壹佰壹拾壹万壹仟壹佰壹拾壹元壹角壹分");
|
||||
map.put("remarks1", "测试收据样式");
|
||||
map.put("payee", "江门市第三人民医院");
|
||||
|
||||
// Map<String, String> map = new HashMap<>();
|
||||
// map.put("departName", "杜阮颐养院");
|
||||
// map.put("payUnit", "苏镜泉");
|
||||
// map.put("hospitalId", "R20081001");
|
||||
// Date date = new Date();
|
||||
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
||||
// map.put("invoiceDate", sdf.format(date));
|
||||
// map.put("projName1", "预付款 2020.10.06 至 2021.02.01");
|
||||
// map.put("oneQian1", "1");
|
||||
// map.put("oneBai1", "1");
|
||||
// map.put("oneShi1", "1");
|
||||
// map.put("oneWan", "1");
|
||||
// map.put("oneQian2", "1");
|
||||
// map.put("oneBai2", "1");
|
||||
// map.put("oneShi2", "1");
|
||||
// map.put("oneYuan", "1");
|
||||
// map.put("oneJiao", "1");
|
||||
// map.put("oneFen", "1");
|
||||
// map.put("priceLite", "¥11111111.11");
|
||||
// map.put("priceBig", "壹仟壹佰壹拾壹万壹仟壹佰壹拾壹元壹角壹分");
|
||||
// map.put("remarks1", "测试收据样式");
|
||||
// map.put("payee", "江门市第三人民医院");
|
||||
|
||||
for (String name : form.getFields().keySet()) {
|
||||
form.setField(name, map.get(name));
|
||||
form.setField(name, values.get(name));
|
||||
}
|
||||
//true代表生成的PDF文件不可编辑
|
||||
stamper.setFormFlattening(false);
|
||||
stamper.setFormFlattening(true);
|
||||
stamper.close();
|
||||
Document doc = new Document();
|
||||
PdfCopy copy = new PdfCopy(doc, out);
|
||||
@ -70,4 +72,44 @@ public class PdfUtils {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void generatePrepaymentPdf(String templatePath, String outputPath, JSONObject params) {
|
||||
|
||||
// 数据转换
|
||||
Map<String, String> values = new HashMap<>();
|
||||
values.put("departName", params.getString("departName"));
|
||||
values.put("payUnit", params.getString("name"));
|
||||
values.put("hospitalId", params.getString("hospitalId"));
|
||||
|
||||
Date date = new Date();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
||||
|
||||
values.put("hospitalId", params.getString("hospitalId"));
|
||||
values.put("invoiceDate", sdf.format(date));
|
||||
values.put("projName1", "预付款");
|
||||
|
||||
BigDecimal prepaid = params.getBigDecimal("prepaid");
|
||||
float prepaidFloat = prepaid.floatValue();
|
||||
Map<String, String> convert = NumberToList.convertTo(prepaidFloat, "1");
|
||||
System.out.println(convert);
|
||||
values.put("fen1", convert.get("fen1"));
|
||||
values.put("jiao1", convert.get("jiao1"));
|
||||
values.put("yuan1", convert.get("yuan1"));
|
||||
values.put("shi1", convert.get("shi1"));
|
||||
values.put("bai1", convert.get("bai1"));
|
||||
values.put("qian1", convert.get("qian1"));
|
||||
values.put("wan1", convert.get("wan1"));
|
||||
values.put("shiwan1", convert.get("shiwan1"));
|
||||
values.put("baiwan1", convert.get("baiwan1"));
|
||||
values.put("qianwan1", convert.get("qianwan1"));
|
||||
|
||||
values.put("priceLite", "¥" + prepaid.toString());
|
||||
|
||||
String convertToHan = NumberToList.convertToHan(prepaidFloat, "1");
|
||||
values.put("priceBig", convertToHan);
|
||||
|
||||
values.put("payee", "江门市第三人民医院");
|
||||
|
||||
fillTemplate(templatePath, outputPath, values);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user