/*
	Antenna House PDF Driver API V7.5
	Java Interface sample program

	概要：入出力ファイルを指定してアドイン変換でPDF出力を行う

	Copyright 2020 Antenna House, Inc.
*/
import jp.co.antennahouse.pdfdriver.pdfdrv.PtlDrvConvert;
import jp.co.antennahouse.pdfdriver.pdfdrv.PtlDrvException;
import jp.co.antennahouse.pdfdriver.pdfdrv.PtlParamExcelAddinSettings;
import jp.co.antennahouse.pdfdriver.pdfdrv.PtlParamPPTAddinSetting;
import jp.co.antennahouse.pdfdriver.pdfdrv.PtlParamWordAddinSetting;

public class Sampleapi02Java {

	public static void main(String[] args) {

		System.out.println("PDF Driver API V7.5 Java サンプル");

        try(PtlDrvConvert conv = new PtlDrvConvert())
        {
            //入出力ファイル名。テスト用の初期値を設定する
            String infile = "C:\\test\\test.docx";
            String outfile = "C:\\sav\\out.pdf";

            //第１引数は入力ファイル名とする
            if (args.length > 0)
            {
                infile = args[0];
            }

            //第２引数は出力ファイル名とする
            if (args.length > 1)
            {
                outfile = args[1];
            }

            // Wordアドイン設定
            PtlParamWordAddinSetting word = new PtlParamWordAddinSetting();
            word.setAttachOriginalFile(true);// true:元のWordファイルを添付する
            word.setBookmarkDestZoom(PtlParamWordAddinSetting.WORDADDIN_DESTZOOM_FIT_PAGE);//しおりの宛先を表示させるときの倍率
            word.setBookmarkOpenLevel(2);//	ファイルを開いたときに表示する階層（1～9）
            word.setConvertComments(true);//true:コメントをノート注釈に変換する
            word.setConvertCrossReferences(true);// true:相互参照と目次をリンクに変換する
            word.setConvertFootnote(true);// true:脚注をリンクに変換する
            word.setOutputBookmarks(true);//true:しおりを出力する
            word.setOutputLinks(true);// true:リンクを出力する
            word.setUseDocumentInformation(true);// true:元文書の文書情報を使用する
            word.setSettingType(PtlParamWordAddinSetting.WORDADDIN_USER_SETTING);// PtlParamWordAddinSettingの設定で出力する
            conv.setParamWordAddinSettings(word);

            // Excelアドイン設定
            PtlParamExcelAddinSettings excel = new PtlParamExcelAddinSettings();
            excel.setAttachOriginalFile(true);// true:元のExcelファイルを添付する
            excel.setConvertAllSheets(true);// true:ワークブック全体を変換する
            excel.setConvertComments(true);// true:コメントをノート注釈に変換する
            excel.setOutputBookmarks(true);// true:しおりを出力する
            excel.setOutputLinks(true);// true:リンクを出力する
            excel.setUseDocumentInformation(true);// true:元文書の文書情報を使用する
            excel.setSettingType(PtlParamExcelAddinSettings.EXCELADDIN_USER_SETTING);// PtlParamExcelAddinSettingの設定で出力する
            conv.setParamExcelAddinSettings(excel);

            // PPTアドイン設定
            PtlParamPPTAddinSetting ppt = new PtlParamPPTAddinSetting();
            ppt.setAttachOriginalFile(true);// true:元のPowerPointファイルを添付する
            ppt.setOutputBookmarks(true);// true:しおりを出力する
            ppt.setOutputLinks(true);// true:リンクを出力する
            ppt.setUseDocumentInformation(true);// true:元文書の文書情報を使用する
            ppt.setSettingType(PtlParamPPTAddinSetting.PPTADDIN_USER_SETTING);// PtlParamPPTAddinSettingの設定で出力する
            conv.setParamPPTAddinSettings(ppt);

            System.out.println("変換開始:" + infile + " -> " + outfile);

            boolean bret = conv.convertFileAddin(infile, outfile);  //アドイン変換
        }
        catch (PtlDrvException ex)
        {
        	System.out.println("error code [" + ex.getErrorCode() + "] : " + ex.getErrorMessage());
        }
        catch (Exception ex)
        {
        	System.out.println("Error : " + ex.getMessage());
        }
        System.out.println("終了");
	}
}
