
PDF文書に設定されているセキュリティ(暗号化情報)を削除します。
PDF文書に設定されているセキュリティを削除して、セキュリティの付いていないPDF文書としての保存ができます。
package cookbook;
import jp.co.antenna.ptl.*;
public class Decrypt {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length < 3)
{
System.out.println("usage: java Decrypt in-pdf-file out-pdf-file in-pdf-password");
return;
}
try (PtlParamInput inputFile = new PtlParamInput(args[0]);
PtlParamOutput outputFile = new PtlParamOutput(args[1]);
PtlPDFDocument doc = new PtlPDFDocument())
{
// パスワードのセット
doc.setPassword(args[2]);
// PDFファイルをロードします。
doc.load(inputFile);
// 暗号化の取得
if (doc.isEncrypted())
{
if (doc.hasOwnerAuthority())
{
// 暗号化の削除
doc.removeEncrypt();
}
else
{
System.out.println("パスワードに処理権限がありません");
return;
}
}
else
{
System.out.println("暗号化されていないファイルです");
return;
}
...【EncryptWithUserPass.javaと同じ処理のため省略
・PtlParamOutputを用いてPtlPDFDocument docの内容を出力
・PtlException, Exception, Error を catchするエラー処理
・finally文で"--完了--"と表示する処理】...
}
}
Decrypt.java
