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();
}
}
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM