From ceeeeff41dfea2a02a02f4cec11eb3628bb1d1af Mon Sep 17 00:00:00 2001 From: gaosong Date: Wed, 19 Oct 2022 14:55:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9PDF=E5=8A=A0=E5=AF=86?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/jero/modules/system/util/PDFUtils.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/util/PDFUtils.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/util/PDFUtils.java index c83b6776c..9738325ef 100644 --- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/util/PDFUtils.java +++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/util/PDFUtils.java @@ -17,6 +17,7 @@ import java.awt.geom.Dimension2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.*; +import java.lang.reflect.Field; @Slf4j public class PDFUtils { @@ -217,7 +218,10 @@ public class PDFUtils { String path = uploadpath + File.separator + fileName; newFilePath = path.replace(fileName, "transformation" + fileName); reader = new PdfReader(byes); - + //解密文件 + Field f = PdfReader.class.getDeclaredField("ownerPasswordUsed"); + f.setAccessible(true); + f.set(reader, Boolean.TRUE); // 加完水印的文件 os = new FileOutputStream(newFilePath); stamper = new PdfStamper(reader, os); @@ -286,6 +290,11 @@ public class PDFUtils { e.printStackTrace(); log.error(e.getMessage()); + } catch (IllegalAccessException e) { + e.printStackTrace(); + log.error(e.getMessage()); + }catch (NoSuchFieldException e) { + e.printStackTrace(); } finally { try { stamper.close();