/* * 既存 PDF にタイムスタンプ付き署名を付与: * 既存の PDF 文書にタイムスタンプ付き署名を行うサンプルです。 * * 必要な製品 : PDFlib PLOP DS 5 * 必要なデータ : demo_signer_rsa_2048.p12 * demo_signer_rsa_2048.p12 は data ディレクトリにあります。 * demo_signer_rsa_2048.p12 のパスワードは demo です。 * RFC3161 に対応したタイムスタンプサーバー * このサンプルでは https://www.infotek.co.jp/tsa を使用します。 */ import java.io.*; import com.pdflib.plop; import com.pdflib.PLOPException; public class certtimestamp { public static void main (String argv[]) { plop plop = null; /* 文書タイムスタンプのための署名オプション */ String sign_opts = "engine=builtin " + "digitalid={filename={demo_signer_rsa_2048.p12}} " + "password={demo} " + "timestamp={source={ " + " url={https://www.infotek.co.jp/tsa} " + " sslverifypeer=false " + "}} "; try { /* 既存 PDF に関する変数を用意する */ String optlist; String searchpath = "../data"; int doc; /* 実行ファイルに渡す引数(取込む既存PDF名・出力するPDF名)のチェックを行う */ if (argv.length > 2) { throw new Exception("usage: certtimestmap >filename> >outfilename>"); } /* PLOP オブジェクトを作成する */ plop = new plop(); /* 読み込みたいファイルの入ったディレクトリを指定する */ optlist = "searchpath {" + searchpath + "} "; plop.set_option(optlist); /* @既存の PDF 文書を開く */ if ((doc = plop.open_document(argv[0], "")) == -1) { throw new Exception("Error: " + plop.get_apiname() + ": " + plop.get_errmsg()); } /* Aタイムスタンプ付き署名を作成する */ if (plop.prepare_signature(sign_opts) == -1) { throw new Exception("Error: " + plop.get_apiname() + ": " + plop.get_errmsg()); } /* Bタイムスタンプ付き署名を PDF に付与して出力する */ if ( plop.create_document(argv[1], "input=" + doc) == -1) { throw new Exception("Error: " + plop.get_apiname() + ": " + plop.get_errmsg()); } /* CPDF文書を閉じる */ plop.close_document(doc, ""); } catch (PLOPException e) { System.err.println("PLOP exception occurred in certtimestamp 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(); } } }