
独自の項目名を持つカスタムプロパティの設定。
文書のプロパティには既定の項目以外にも独自の項目名を持つカスタムプロパティを設定できます。カスタムプロパティは任意の数追加できます。
本サンプルプログラムでは、入力PDFにカスタムプロパティを1つ追加してPDFドキュメントとして出力します。コマンドライン引数でカスタムプロパティの名前と値を指定します。
package cookbook;
import jp.co.antenna.ptl.*;
public class SetCustomDocProperty {
// そのクラスのusageを表示する関数
private static void printUsage() {
System.out.println("usage: java SetDocInfo in-pdf-file out-pdf-file" +
" custom-prop-name custom-prop-value");
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length < 4) {
printUsage();
return;
}
try (PtlParamInput inputFile = new PtlParamInput(args[0]);
PtlParamOutput outputFile = new PtlParamOutput(args[1]);
PtlPDFDocument doc = new PtlPDFDocument()) {
// PDFファイルをロード
doc.load(inputFile);
try (PtlDocProperty docProperty = doc.getDocProperty(); //PDFの文書プロパティ
PtlCustomProperties customProperties = docProperty.getCustomProperties();
PtlCustomProperty newCustomProp = new PtlCustomProperty(args[2],
args[3])) {
customProperties.append(newCustomProp);
}
// ファイルに保存します
doc.save(outputFile);
}
...【AppendAnnotStampDefault.javaと同じ処理のため省略
・エラーメッセージ処理と出力】...
}
}
SetCustomDocProperty.java
C:\samples>java cookbook.SetCustomDocProperty usage: java SetDocInfo in-pdf-file out-pdf-file custom-prop-name custom-prop-value C:\samples>java cookbook.SetCustomDocProperty blank.pdf blank-setcustominfo.pdf 本の名前 PDFCookBookVol.4 -- 完了 --
次図はAdobe Readerでカスタムプロパティを設定したPDFのカスタムプロパティを表示したところです。
