/*
    Antenna House PDF Tool API V7.0
    Java Interface sample program

    概要：文書情報の取得

    Copyright 2015-2021 Antenna House, Inc.
*/

package Sample;

import jp.co.antenna.ptl.*;

public class GetDocInfo {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        if (args.length < 1)
        {
            System.out.println("usage: java GetDocInfo in-pdf-file");
            return;
        }

        try (PtlParamInput inputFile = new PtlParamInput(args[0]);
             PtlPDFDocument doc = new PtlPDFDocument())
        {
            // PDFファイルをロード
            doc.load(inputFile);

            try (PtlDocProperty docProperty = doc.getDocProperty(); //PDFの文書プロパティ
                 PtlDocInfo docinf = docProperty.getDocInfo()) {    //PDFの文書情報

                // タイトル取得
                System.out.println("Title : " + docinf.getTitle());

                // 著者取得
                System.out.println("Author : " + docinf.getAuthor());

                // サブジェクト取得
                System.out.println("Subject : " + docinf.getSubject());

                // キーワード取得
                System.out.println("Keywords : " + docinf.getKeywords());

                // クリエータ取得
                System.out.println("Creator : " + docinf.getCreator());

                // プロデューサ取得
                System.out.println("Producer : " + docinf.getProducer());

                // 作成日付を取得
                try (PtlDate dateCreate = docinf.getCreationDate())
                {
                    System.out.println("CreationDate : "
                        + dateCreate.getYear()
                        + "/" + dateCreate.getMonth()
                        + "/" + dateCreate.getDay()
                        + " " + dateCreate.getHour()
                        + ":" + dateCreate.getMin()
                        + ":" + dateCreate.getSec());
                }

                // 更新日付を取得
                try (PtlDate dateMod = docinf.getModDate())
                {
                    System.out.println("ModDate : "
                        + dateMod.getYear()
                        + "/" + dateMod.getMonth()
                        + "/" + dateMod.getDay()
                        + " " + dateMod.getHour()
                        + ":" + dateMod.getMin()
                        + ":" + dateMod.getSec());
                }
            }
        }
        catch(PtlException pex) {
            System.out.println("PtlException : ErrorCode = " + pex.getErrorCode() + "\n  " + pex.getErrorMessage());
        }
        catch(Exception ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }
        catch (Error ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }
        finally {
            System.out.println("-- 完了 --");
        }
    }
}
