/* * パスワードを用いて暗号化: * 暗号化されていない PDF 文書を、ユーザー・マスターパスワードを用いて暗号化します。 * * 必要な製品 : PDFlib PLOP 5 又は PDFlib PLOP DS 5 */ import java.io.*; import com.pdflib.PLOPException; import com.pdflib.plop; public class encrypt { public static void main (String argv[]) { plop plop = null; try { /* 既存 PDF に関する変数を用意する */ final String in_filename = "PLOP-datasheet.pdf"; final String in_password = ""; String optlist; /* 出力する新規 PDF に関する変数を用意する */ final String out_filename = "PLOP-datasheet-encrypted.pdf"; final String out_master = "DEMO"; final String out_user = "demo"; final String permissions = ""; int doc; /* 本サンプルに必要なデータが保存されているディレクトリを指定する */ final String searchpath = "../data"; /* PLOP オブジェクトを作成する */ plop = new plop(); /* 読み込みたいファイルの入ったディレクトリを指定する */ optlist = "searchpath={" + searchpath + "}"; plop.set_option(optlist); /* @既存の PDF 文書を開く */ optlist = "password {" + in_password + "} "; if ((doc = plop.open_document(in_filename, optlist)) == -1) { System.err.println("Error: " + plop.get_errmsg()); plop.delete(); System.exit(2); } /* Aパスワードを付与して PDF を出力する */ optlist = "masterpassword {" + out_master + "} userpassword {" + out_user + "} permissions {" + permissions + "} " +"input="+ doc; if (plop.create_document(out_filename, optlist) == -1) { System.err.println("Error: " + plop.get_errmsg()); plop.delete(); System.exit(2); } /* BPDF 文書を閉じる */ plop.close_document(doc, ""); } catch (PLOPException e) { System.err.println("PLOP exception occurred in encrypt sample:"); System.err.println("[" + e.get_errnum() + "] " + e.get_apiname() + ": " + e.get_errmsg()); } catch (Exception e) { System.err.println(e); } finally { /* PLOP オブジェクトを削除する */ if (plop != null) plop.delete(); } } }