JAva PDF暗号化情報の取得

7355 ワード

importjava.io.FileOutputStream;

importcom.lowagie.text.pdf.PdfEncryptor;
importcom.lowagie.text.pdf.PdfReader;
importcom.lowagie.text.pdf.PdfStamper;
importcom.lowagie.text.pdf.PdfWriter;

publicclassMainClass{

publicstaticvoidmain(String[]args)throwsException{
PdfReaderreader=newPdfReader("1.pdf");
PdfStamperstamper=newPdfStamper(reader,newFileOutputStream("Encrypted1.pdf"));
stamper.setEncryption("Hello".getBytes(),"World".getBytes(),PdfWriter.AllowPrinting
|PdfWriter.AllowCopy,PdfWriter.STRENGTH40BITS);
stamper.close();

getEncryptionInformation("1.pdf",null);
getEncryptionInformation("Encrypted1.pdf","World");
}

publicstaticvoidgetEncryptionInformation(Stringfilename,Stringownerpassword)
throwsException{
PdfReaderreader;
if(ownerpassword==null)
reader=newPdfReader(filename);
else
reader=newPdfReader(filename,ownerpassword.getBytes());
System.out.println("Encrypted?"+reader.isEncrypted());
if(reader.isEncrypted()){
System.out.println("Permissions:"
+PdfEncryptor.getPermissionsVerbose(reader.getPermissions()));
System.out.println("128bit?"+reader.is128Key());
}
}

}