itext pdf加密

package com.jms.cfc.bpm.web.controller.search;

import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;

public class GeneratePDF {
private static String USER_PASS = "Hello123";
private static String OWNER_PASS = "Owner123";

public static void main(String[] args) {
try {
InputStream is = new FileInputStream(new File("D:/123.pdf"));
PdfReader pdfReader = new PdfReader(is);
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream("D:/123.pdf"));
pdfStamper.setEncryption(USER_PASS.getBytes(), OWNER_PASS.getBytes(), 0, PdfWriter.ENCRYPTION_AES_256);
pdfStamper.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

  

posted @ 2021-10-13 13:30  奇异宝  阅读(449)  评论(0编辑  收藏  举报