修改PDF加密文件的问题
This commit is contained in:
+10
-1
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user