diff --git a/yxt-common/yxt-common-base/pom.xml b/yxt-common/yxt-common-base/pom.xml index ff5d339..3cb7514 100644 --- a/yxt-common/yxt-common-base/pom.xml +++ b/yxt-common/yxt-common-base/pom.xml @@ -120,12 +120,6 @@ javase 3.3.2 - - - com.itextpdf - itextpdf - 5.4.3 - org.apache.httpcomponents httpclient @@ -165,17 +159,11 @@ hutool-all ${hutool.version} - org.freemarker freemarker 2.3.29 - - com.jacob - jacob - 1.18 - javax.xml.bind jaxb-api @@ -196,6 +184,26 @@ activation 1.1.1 + + com.jacob + jacob + 1.18 + + + com.itextpdf + itextpdf + 5.5.11 + + + com.itextpdf + itext-asian + 5.2.0 + + + org.apache.pdfbox + pdfbox + 2.0.25 + diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java index 505ec44..5561fc1 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/DocPdfComponent.java @@ -35,6 +35,12 @@ public class DocPdfComponent { @Value("${templateUrl.prefixUrl:http://127.0.0.1:8080/template/}") private String prefixTemplateUrl; +/* @Value("${templateUrl.uploadPdfUrl:http://127.0.0.1:8080/template/pdf/}") + private String uploadPdfUrl; + + @Value("${templateUrl.prefixPdfUrl:http://127.0.0.1:8080/template/pdf/}") + private String prefixPdfUrl;*/ + /** * 根据ftl模板生成word * @@ -44,7 +50,6 @@ public class DocPdfComponent { * @return 返回word文件路径和链接路径 */ public Map creatWord(Map map, String typeName, String fileName) { -// String dateStr = DateUtils.dateConvertStr(new Date(), "yyyyMMdd"); String dateStr = DateUtil.format(new Date(), "yyyyMMdd"); String targetPath = uploadTemplateUrl + dateStr; try { @@ -171,4 +176,12 @@ public class DocPdfComponent { public String getPrefixTemplateUrl() { return prefixTemplateUrl; } + + /* public String getUploadPdfUrl() { + return uploadPdfUrl; + } + + public String getPrefixPdfUrl() { + return prefixPdfUrl; + }*/ } diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/FileUploadComponent.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/FileUploadComponent.java index 271348e..120f377 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/FileUploadComponent.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/component/FileUploadComponent.java @@ -87,7 +87,8 @@ public class FileUploadComponent { //2021.10.16 截取文件后缀名以外的名字 String prefixName = fileName.substring(0, fileName.indexOf(".")); // 新文件名:文件原名称 + ‘-’ + 生成的时间戳 2021.10.16 - String filePath = prefixName + "_" + dateFileName() + suffixName; +// String filePath = prefixName + "_" + dateFileName() + suffixName; + String filePath = dateFileName() + suffixName; if (hasDateDir) { String dateStr = DateUtil.format(new Date(), "yyyyMMdd"); // 增加日期目录 diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/web/FileController.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/web/FileController.java index 9474215..bb73538 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/web/FileController.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/web/FileController.java @@ -100,7 +100,6 @@ public class FileController { @GetMapping("/download") public ResultBean download(@RequestParam(value = "filePath") String filePath, @RequestParam(value = "outFileName") String outFileName) { ResultBean rb = ResultBean.fireFail(); - File file = fileUploadComponent.findFileByPath(filePath); if (file == null) return rb.setMsg("文件不存在"); diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/JPushServer.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/JPushServer.java index cdac8a4..d887bab 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/JPushServer.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/JPushServer.java @@ -141,6 +141,40 @@ public class JPushServer { } } + /** + * 待阅消息推送(使用别名) + * @param title 标题 + * @param content 内容 + * @param msg_type 消息类别 + */ + public static void sendPushAliass(String title, String content, String state, String name, String... alias) { + Map extras = new HashMap<>(); + extras.put("class_name", "com.anrui.android.activity.ReadActivity"); + extras.put("state", "0"); + extras.put("name", name); + ClientConfig clientConfig = ClientConfig.getInstance(); + final JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, clientConfig); + + final PushPayload payload = buildPushObject_android_and_iosAlias(title, content, "com.anrui.android.activity.ReadActivity", extras, alias); + try { + PushResult result = jpushClient.sendPush(payload); + System.out.println("Got result - " + result); + // 如果使用 NettyHttpClient,需要手动调用 close 方法退出进程 + // jpushClient.close(); + } catch (APIConnectionException e) { + System.out.println("Connection error. Should retry later. "+e); + System.out.println("Sendno: " + payload.getSendno()); + + } catch (APIRequestException e) { + System.out.println("Error response from JPush server. Should review and fix it. "+ e); + System.out.println("HTTP Status: " + e.getStatus()); + System.out.println("Error Code: " + e.getErrorCode()); + System.out.println("Error Message: " + e.getErrorMessage()); + System.out.println("Msg ID: " + e.getMsgId()); + System.out.println("Sendno: " + payload.getSendno()); + } + } + /** * (广播) * @param title 标题 diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/TransformMoney.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/TransformMoney.java new file mode 100644 index 0000000..d94d1dd --- /dev/null +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/TransformMoney.java @@ -0,0 +1,200 @@ +package com.yxt.common.base.utils; + +import java.math.BigDecimal; + +/** + * @Author dimengzhe + * @Date 2022/11/8 19:10 + * @Description + */ +public class TransformMoney { + + /* +以下摘自百度百科:http://baike.baidu.com/view/359995.htm +大写数字规则 + 中文大写金额数字应用正楷或行书填写,如壹、贰、叁、肆、伍、陆、柒、捌、玖、拾、佰、仟、万、亿、元、角、分、零、整(正)等字样。不得用一、二(两)、三、四、五、六、七、八、九、十、廿、毛、另(或0)填写,不得自造简化字。如果金额数字书写中使用繁体字,如贰、陆、亿、万、圆的,也可。 + 中文大写金额数字到"元"为止的,在"元"之后,应写"整"(或"正")字,在"角"之后,可以不写"整"(或"正")字。大写金额数字有"分"的,"分"后面不写"整"(或"正")字。 + 中文大写金额数字前应标明"人民币"字样,大写金额数字有"分"的,"分"后面不写"整"(或"正")字。 + 中文大写金额数字前应标明"人民币"字样,大写金额数字应紧接"人民币"字样填写,不得留有空白。大写金额数字前未印"人民币"字样的,应加填"人民币"三字。在票据和结算凭证大写金额栏内不得预印固定的"仟、佰、拾、万、仟、佰、拾、元、角、分"字样。 + 阿拉伯数字小写金额数字中有"0"时,中文大写应按照汉语语言规律、金额数字构成和防止涂改的要求进行书写。举例如下: + 阿拉伯数字中间有"0"时,中文大写要写"零"字,如¥1409.50,应写成人民币壹仟肆佰零玖元伍角。 + 阿拉伯数字中间连续有几个"0"时,中文大写金额中间可以只写一个"零"字,如¥6007.14,应写成人民币陆仟零柒元壹角肆分。 + 阿拉伯金额数字万位和元位是"0",或者数字中间连续有几个"0",万位、元位也是"0",但千位、角位不是"0"时,中文大写金额中可以只写一个零字,也可以不写"零"字。如¥1680.32,应写成人民币壹仟陆佰捌拾元零叁角贰分,或者写成人民币壹仟陆佰捌拾元叁角贰分,又如¥107000.53,应写成人民币壹拾万柒仟元零伍角叁分,或者写成人民币壹拾万零柒仟元伍角叁分。 + 阿拉伯金额数字角位是"0",而分位不是"0"时,中文大写金额"元"后面应写"零"字。如¥16409.02,应写成人民币壹万陆仟肆佰零玖元零贰分;又如¥325.04,应写成人民币叁佰贰拾伍元零肆分。 +*/ + + static final String big = "零壹贰叁肆伍陆柒捌玖"; //大写 + static final String[] units = {"仟佰拾", "角分"}; //单位 + + + /** + * 双精度浮点数转换成字符串 + * 注: + * 1、如果直接用String.toString(double d)方法,超大数额会出现科学计数法的字符串; + * 2、如果整数部分超过15位数,低位部分可能出现误差,所以不支持超过15位整数的数值, + * 一般数据库设计金额字段时都不会超过15位整数,如oracle用Number(18,3)的类型表示,整数部分最多15位,小数点后保留3位有效数字。 + */ + public static String getDecimalStr(double d) { + //设置小数点后的精度,保留两位 + /*四舍五入结果参考: + 0.005,//0.01入 + 0.015,//0.01舍 + 0.025,//0.03入 + 0.035,//0.04入 + 0.045,//0.04舍 + 0.055,//0.06入(前一位是5则入) + */ + String str = new BigDecimal(d).setScale(2, BigDecimal.ROUND_HALF_UP).toString(); + + /* + //经过测试,以下三种方法都是可以用的: + //或1: + String str = new BigDecimal(d).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString(); + + //或2: + DecimalFormat format = new DecimalFormat(); + format.applyPattern("#################0.00"); + String str = format.format(d); + + //或3: + DecimalFormat decimalFormat = new DecimalFormat(); + decimalFormat.setMinimumFractionDigits(2); + decimalFormat.setMaximumFractionDigits(2); + decimalFormat.setGroupingUsed(false); + decimalFormat.setMaximumIntegerDigits(15); + decimalFormat.setMinimumIntegerDigits(15); + str=decimalFormat.format(d); + */ + + //如果结果是整数,则去掉尾巴 + if (str.endsWith(".00")) { + str = str.replace(".00", ""); + } + return str; + } + + /** + * 金额是double类型的要先转换成字符串 + * + * @param money 金额 + */ + public static String transform(double money) { + String moneyStr = getDecimalStr(money); + return transform(moneyStr); + } + + /** + * 金额转换成大字 + * 我的思路: + * 1、double数值转换成数值字符串 + * 2、处理整数部分: + * 填充到16位,不足16位则前面补'0',然后右起分成四组,每组根据"x仟x佰x拾x"的规则转换成大写,若该组为"0000"则结果是"零"; + * 对这四组结果从高位到低位拼接起来,规则:[组4]万[组3]亿[组2]万[组1]圆。 + * 3、处理小数部分(不多说) + */ + public static String transform(String moneyStr) { + String[] parts = moneyStr.split("\\."); //区别整数、小数部分 + String result = ""; + + //处理整数部分 + int length = parts[0].length(); //整数部分的位数 + if (length > 15) { + return "金额太大,不能处理整数部分超过15位的金额!"; + } + String intPart = parts[0]; + + //填充到16位,因为是分4组,每组4个数字 + while (intPart.length() < 16) { + intPart = '0' + intPart; + } + //共分四组,右起四位一组,例如:0001,2003,0030,3400 + String[] groups = new String[4]; + for (int i = 0; i < groups.length; i++) { + int start = intPart.length() - (i + 1) * 4; //开始位置 + int end = intPart.length() - i * 4; //结束位置 + groups[i] = intPart.substring(start, end); + groups[i] = transformGroup(groups[i]); //当前组的四位数字转换成大写 + } + + //对这四组结果从高位到低位拼接起来,规则:[组4]万[组3]亿[组2]万[组1]圆 + for (int i = groups.length - 1; i >= 0; i--) { + if (i == 3) { //第四组:万亿级 + if (!"零".equals(groups[i])) { + result += groups[i] + "万"; + } + } else if (i == 2) { //第三组:亿级 + if (!"零".equals(groups[i])) { + result += groups[i] + "亿"; + } else { + if (result.length() > 0) { + result += "亿"; + } + } + } else if (i == 1) { //第二组:万级 + if (!"零".equals(groups[i])) { + result += groups[i] + "万"; + } else if (!groups[i].startsWith("零")) { + result += groups[i]; + } + } else { //第一组:千级 + if (!"零".equals(groups[i]) || result.length() == 0) { + result += groups[i]; + } + result += "元"; + } + } + if (!"零元".equals(result) && result.startsWith("零")) { + result = result.substring(1, result.length()); //最前面的可能出现的“零”去掉 + } + + //处理小数部分 + if (parts.length == 2) { + String decimalPart = parts[1]; //小数部分 + if ("0".equals(decimalPart)){//小数为零,则加上“整” + result += "整"; + }else { + for (int i = 0; i < decimalPart.length(); i++) { + int num = Integer.valueOf(decimalPart.charAt(i) + ""); //提取数字,左起 + result += big.charAt(num) + "" + units[1].charAt(i); //数字变大写加上单位 + } + result = result.replace("零角", "零"); //去掉"零角"的"角" + result = result.replace("零分", ""); //去掉"零分" + } + } else { + result += "整"; //没有小数部分,则加上“整” + } + return result; + } + + /** + * 处理整数部分的组,右起每四位是一组 + * + * @param group 四位数字字符串 + */ + public static String transformGroup(String group) { + String result = ""; + int length = group.length(); + for (int i = 0; i < length; i++) { + int digit = Integer.valueOf(group.charAt(i) + ""); //单个数字,左起 + String unit = ""; //单位 + if (i != length - 1) { + unit = units[0].charAt(i) + ""; + } + result += big.charAt(digit) + unit; //数字变大写加上单位 + } + + result = result.replace("零仟", "零"); + result = result.replace("零佰", "零"); + result = result.replace("零拾", "零"); + + while (result.contains("零零")) { + result = result.replace("零零", "零"); //如果有“零零”则变成一个“零” + } + + if (!"零".equals(result) && result.endsWith("零")) { + result = result.substring(0, result.length() - 1); //最未尾的可能出现的“零”去掉 + } + return result; + } + +} diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java index dbef38f..bc30708 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordConvertUtils.java @@ -1,14 +1,20 @@ package com.yxt.common.base.utils; +import com.itextpdf.text.BaseColor; +import com.itextpdf.text.Element; +import com.itextpdf.text.Rectangle; +import com.itextpdf.text.pdf.*; import com.jacob.activeX.ActiveXComponent; import com.jacob.com.ComThread; import com.jacob.com.Dispatch; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.Version; +import org.apache.pdfbox.io.MemoryUsageSetting; +import org.apache.pdfbox.multipdf.PDFMergerUtility; import java.io.*; -import java.util.Date; +import java.util.List; import java.util.Map; /** @@ -22,13 +28,11 @@ public class WordConvertUtils { * 根据ftl模板生成word * * @param map 数据 - * @param typeName 模板名称 - * @param sourcePath 模板路径 * @param targetPath 保存目标路径 * @param fileName 文件名 */ public static void creatWord(Map map, File file, String targetPath, String fileName, String dir) { - String curDate = DateUtils.dateConvertStr(new Date(), "yyyy年MM月dd日"); +// String curDate = DateUtils.dateConvertStr(new Date(), "yyyy年MM月dd日"); try { //Configuration 用于读取ftl文件 Configuration configuration = new Configuration(new Version("2.3.0")); @@ -46,12 +50,57 @@ public class WordConvertUtils { Template template = configuration.getTemplate(file.getName(), "utf-8"); Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"), 10240); template.process(map, out); + file.delete(); out.close(); } catch (Exception e) { e.printStackTrace(); } } + public static void creatWord1(Map map, File file, String targetPath, String fileName, File dir) { +// String curDate = DateUtils.dateConvertStr(new Date(), "yyyy年MM月dd日"); + try { + //Configuration 用于读取ftl文件 + Configuration configuration = new Configuration(new Version("2.3.0")); + configuration.setDefaultEncoding("utf-8"); + //指定路径的第二种方式 + configuration.setDirectoryForTemplateLoading(dir); + //输出文档路径及名称 + File targetFile = new File(targetPath); + if (!targetFile.exists()) { + targetFile.mkdirs(); + } + targetPath = targetPath + fileName; + File outFile = new File(targetPath); + //以utf-8的编码读取ftl文件 + Template template = configuration.getTemplate(file.getName(), "utf-8"); + Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"), 10240); + template.process(map, out); + file.delete(); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void inputStreamToFile(InputStream ins, File file) { + OutputStream os = null; + try { + os = new FileOutputStream(file); + int bytesRead = 0; + byte[] buffer = new byte[8192]; + while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) { + os.write(buffer, 0, bytesRead); + } + os.close(); + ins.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + /** * word转换为pdf * @@ -95,7 +144,90 @@ public class WordConvertUtils { System.out.println("关闭文档"); // 如果没有这句话,winword.exe进程将不会关闭 ComThread.Release(); + new File(wordFile).delete(); + } + } + + /** + * @param inputFile 源文件全路径:你的PDF文件地址 + * @param outputFile 输出全路径:添加水印后生成PDF存放的地址 + * @param outDir 添加水印后生成PDF存放的目录 + * @param waterMarkName 你的水印 + * @return 注意:源文件全路径和输出全路径最好不要写同一样的,不然有可能会报“java.io.FileNotFoundException:请求的操作无法在使用用户映射区域打开的文件上执行”的错误 + */ + public static boolean waterMark(String inputFile, String outputFile, String outDir, String waterMarkName) { + try { + File targetFile = new File(outDir); + if (!targetFile.exists()) { + targetFile.mkdirs(); + } + PdfReader reader = new PdfReader(inputFile); + PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputFile)); + // 这里的字体设置比较关键,这个设置是支持中文的写法 + BaseFont base = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);// 使用系统字体 + int total = reader.getNumberOfPages() + 1; + PdfContentByte under; + Rectangle pageRect = null; + for (int i = 1; i < total; i++) { + pageRect = stamper.getReader().getPageSizeWithRotation(i); + // 计算水印X,Y坐标 +// float x = pageRect.getWidth() / 10; +// float y = pageRect.getHeight() / 10 - 10; + float x = 290; + float y = 400; + // 获得PDF最顶层 + under = stamper.getOverContent(i); + under.saveState(); + // set Transparency + PdfGState gs = new PdfGState(); + // 设置透明度为0.2 +// gs.setFillOpacity(1.f); + gs.setFillOpacity(0.3f); + under.setGState(gs); + under.restoreState(); + under.beginText(); + under.setFontAndSize(base, 35); +// under.setColorFill(BaseColor.ORANGE); + under.setColorFill(BaseColor.BLACK); + + // 水印文字成45度角倾斜 + under.showTextAligned(Element.ALIGN_CENTER, waterMarkName, x, y, 45); + // 添加水印文字 + under.endText(); + under.setLineWidth(1f); + under.stroke(); + } + stamper.close(); + reader.close(); + new File(inputFile).delete(); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; } + } + /** + * pdf合并 + * + * @param files 源文件的相对路径 + * @param targetPath 输出的pdf的路径 + * @return + * @throws Exception + */ + public static File mulFile2One(List files, String targetPath) throws Exception { + PDFMergerUtility mergePdf = new PDFMergerUtility(); + for (File f : files) { + if (f.exists() && f.isFile()) { + // 循环添加要合并的pdf + mergePdf.addSource(f); + } + } + // 设置合并生成pdf文件名称 + mergePdf.setDestinationFileName(targetPath); + // 合并pdf + mergePdf.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly()); + //ToDo:根据需求实现是否要删除源文件 + return new File(targetPath); } } diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java index 15a7bae..e9cf724 100644 --- a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/utils/WordUtils.java @@ -4,6 +4,7 @@ import cn.hutool.core.codec.Base64; import com.jacob.activeX.ActiveXComponent; import com.jacob.com.ComThread; import com.jacob.com.Dispatch; +import com.jacob.com.Variant; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.Version; @@ -84,6 +85,18 @@ public class WordUtils { * @param pdfName pdf名称 */ public static void doc2pdf(String wordFile, String pdfPath, String pdfName) { + doc2pdf( wordFile, pdfPath, pdfName,""); + } + + /** + * word转换为pdf + * + * @param wordFile word的路径 + * @param pdfPath pdf的路径 + * @param pdfName pdf名称 + * @param mark 水印 + */ + public static void doc2pdf(String wordFile, String pdfPath, String pdfName,String mark) { ActiveXComponent app = null; System.out.println("开始转换..."); long start = System.currentTimeMillis(); @@ -97,6 +110,10 @@ public class WordUtils { // 打开文档 document = Dispatch.call(documents, "Open", wordFile, false, true).toDispatch(); // 如果文件存在的话,不会覆盖,会直接报错,所以我们需要判断文件是否存在 + if (StringUtils.isNotBlank(mark)){ + addWatermark(app,documents,document,wordFile,wordFile,mark); + } + //setWaterMark(app,mark); File targetFile = new File(pdfPath); if (!targetFile.exists()) { targetFile.mkdirs(); @@ -125,15 +142,81 @@ public class WordUtils { } + public static void addWatermark(ActiveXComponent wordApp, Dispatch documents,Dispatch doc,String src, String des, String text) throws Exception { + ComThread.InitMTA(); + // 文档隐藏时进行应用操作 + wordApp.setProperty("Visible", new Variant(false)); + // 实例化模板Workbooks对象 + //打开文件 + Dispatch docSelect = Dispatch.get(wordApp, "Selection").toDispatch(); + //取得活动窗体对象 + Dispatch activeDoc = wordApp.getProperty("ActiveWindow").toDispatch(); + try { + //添加水印,多个水印 + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 4; j++) { + //取得活动窗体对象 + Dispatch activePan = Dispatch.get(activeDoc, "ActivePane").toDispatch(); + //取得视窗对象 + Dispatch view = Dispatch.get(activePan, "View").toDispatch(); + //打开页眉 + Dispatch.put(view, "SeekView", new Variant(1)); + //获取页眉和页脚 + Dispatch headfooter = Dispatch.get(docSelect, "HeaderFooter") + .toDispatch(); + //取得图形对象 + Dispatch shapes = Dispatch.get(headfooter, "Shapes").toDispatch(); + /**插入文字,并转为图片: + * 操作对象、方法、艺术字格式、水印内容、字体、字体大小、字体是否粗体、字体是否斜体、左边距、上边距 + */ + Dispatch selection = Dispatch.call(shapes, "AddTextEffect", + new Variant(9), text, "宋体", new Variant(10), + new Variant(false), new Variant(false), new Variant(0), + new Variant(0)).toDispatch(); + //选中当前文档水印 + Dispatch.call(selection, "Select"); + Dispatch shapeRange = Dispatch.get(docSelect, "ShapeRange") + .toDispatch(); + Dispatch textEffect = Dispatch.get(shapeRange, "TextEffect") + .toDispatch(); + Dispatch.put(textEffect, "NormalizedHeight", new Boolean(false)); + Dispatch line = Dispatch.get(shapeRange, "Line").toDispatch(); + Dispatch.put(line, "Visible", new Boolean(false)); + Dispatch fill = Dispatch.get(shapeRange, "Fill").toDispatch(); + Dispatch.put(fill, "Visible", new Boolean(true)); + // 设置水印透明度 + Dispatch.put(fill, "Transparency", new Variant(0.1)); + Dispatch foreColor = Dispatch.get(fill, "ForeColor").toDispatch(); + //设置水印颜色 + Dispatch.put(foreColor, "RGB", new Variant(16711620)); + Dispatch.call(fill, "Solid"); + // 设置水印旋转 + Dispatch.put(shapeRange, "Rotation", new Variant(315)); + Dispatch.put(shapeRange, "LockAspectRatio", new Boolean(true)); + //设置水印宽高 + Dispatch.put(shapeRange, "Height", new Variant(2.2)); + Dispatch.put(shapeRange, "Width", new Variant(18)); + //设置水印位置,相对左上角 + Dispatch.put(shapeRange, "Left", new Variant(j * 120 - 60)); + Dispatch.put(shapeRange, "Top", new Variant(i * 270)); + //恢复视图 + Dispatch.put(view, "SeekView", new Variant(0)); + } + } + //另存为目标文件 + Dispatch.call(doc, "SaveAS",des,new Variant(true) ); + } catch (Exception e) { + e.printStackTrace(); + } finally { + System.out.println("关闭文档"); + } + } public static void main(String[] args) { Map dataMap = new HashMap(); String curDate = DateUtils.dateConvertStr(new Date(), "yyyy年MM月dd日"); dataMap.put("partyA", "甲方卖出方"); dataMap.put("partyB", "乙方买受方"); - // 图片 -// dataMap.put("imgStr1", getImageStr("D:\\fileTest\\name.png")); -// dataMap.put("imgStr2", getImageStr("D:\\fileTest\\zhang.png")); // 列表 Car car1 = new Car("奔驰", "1001", "v10"); Car car2 = new Car("宝马", "1002", "v10"); diff --git a/yxt-common/yxt-common-core/src/main/java/com/yxt/common/core/domain/BaseEntity.java b/yxt-common/yxt-common-core/src/main/java/com/yxt/common/core/domain/BaseEntity.java index c9380fe..5cf3770 100644 --- a/yxt-common/yxt-common-core/src/main/java/com/yxt/common/core/domain/BaseEntity.java +++ b/yxt-common/yxt-common-core/src/main/java/com/yxt/common/core/domain/BaseEntity.java @@ -130,7 +130,6 @@ public class BaseEntity extends EntityWithId { @ApiModelProperty("字符型编号") private String sid = UUID.randomUUID().toString(); - // @Version @ApiModelProperty("记录版本,锁") private Integer lockVersion = 0; diff --git a/yxt-parent/pom.xml b/yxt-parent/pom.xml index 58a8876..eeabf10 100644 --- a/yxt-parent/pom.xml +++ b/yxt-parent/pom.xml @@ -77,6 +77,8 @@ 4.1.2 6.5.0 + 2.0.25 + @@ -401,56 +403,62 @@ + + org.apache.pdfbox + pdfbox + ${pdfbox.version} + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - nexus-releases - http://nexus3.yyundong.com/repository/yxt-mvn-releases/ - - - nexus-snapshots - http://nexus3.yyundong.com/repository/yxt-mvn-snapshot/ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + nexus-releases + http://nexus3.yyundong.com/repository/yxt-mvn-releases/ + + + nexus-snapshots + http://nexus3.yyundong.com/repository/yxt-mvn-snapshot/ + + \ No newline at end of file