java之PDF签名保护,禁止修改复制打印.

Shaka 3月前 ⋅ 111 阅读

 

我的方法名可能有点奇怪.备注加的不全,可能不太准确,知道的可以留言告诉我以下.谢谢.

private void readOnly(String path){
try {
PdfReader.unethicalreading = true;
PdfReader reader = new PdfReader(new FileInputStream(path));//已加密的文件
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(path));

byte[] ownerPassword = "12345".getBytes();
stamper.setEncryption(null, ownerPassword, PdfWriter.ALLOW_ASSEMBLY, false);
stamper.setEncryption(null, ownerPassword, PdfWriter.ALLOW_COPY, false); //允许复制
stamper.setEncryption(null, ownerPassword, PdfWriter.ALLOW_DEGRADED_PRINTING, false);//允许降级打印
stamper.setEncryption(null, ownerPassword, PdfWriter.ALLOW_FILL_IN, false); //允许写入
stamper.setEncryption(null, ownerPassword, PdfWriter.ALLOW_MODIFY_ANNOTATIONS, false); //允许修改注解
stamper.setEncryption(null, ownerPassword, PdfWriter.ALLOW_MODIFY_CONTENTS, false); //允许修改内容
stamper.setEncryption(null, ownerPassword, PdfWriter.ALLOW_PRINTING, false); //允许打印
stamper.setEncryption(null, ownerPassword, PdfWriter.ALLOW_SCREENREADERS, false);
stamper.setEncryption(null, ownerPassword, PdfWriter.DO_NOT_ENCRYPT_METADATA, false); //不加密源数据
stamper.setViewerPreferences(PdfWriter.HideToolbar|PdfWriter.HideMenubar);
stamper.close();
reader.close();
} catch(Exception e) {
e.printStackTrace();
}
}

注意:本文归作者所有,未经作者允许,不得转载

全部评论: 0

    我有话说: