﻿/*
	Antenna House PDF Tool API V7.0
	C++ Interface sample program

	概要：PDF/A-1b,PDF/A-2bへの変換

	Copyright 2021 Antenna House,Inc.
*/
#include < PdfTk.h >

using namespace std;
using namespace PdfTk;

int main(int argc, char* argv[])
{
	if (argc < 4)
	{
		printf("usage: FixUpPDFA.exe in-pdf-file out-pdf-file 規格\n");
		printf("規格\n1 : PDF/A-1b  2 : PDF/A-1b\n");
		return 1;
	}
	try {
		PtlPDFFixUp::PDFA_TYPE type;
		std::string desc;
		const char* kind = argv[3];
		switch (kind[0]) {
		case '1':
			type = PtlPDFFixUp::PDFA_1B;
			desc = "PDF/A-1b";
			break;
		case '2':
			type = PtlPDFFixUp::PDFA_2B;
			desc = "PDF/A-2b";
			break;
		default:
			printf("usage: FixUpPDFA.exe in-pdf-file out-pdf-file 適用規格\n");
			printf("適用規格\n1 : PDF/A-1b  2 : PDF/A-1b\n");
			return 1;
		}

		PtlParamInput input(argv[1]);
		PtlParamOutput output(argv[2]);
		PtlPDFFixUp fix;
		//PtlParamInput iccpcmyk("JapanColor2001Coated.icc");
		//PtlParamInput iccprgb("sRGB2014.icc");
		PtlParamInput iccpcmyk("D:\\Develop\\AHPDFFixUp\\icc\\JapanColor2001Coated.icc");
		PtlParamInput iccprgb("D:\\Develop\\AHPDFFixUp\\icc\\sRGB2014.icc");

		fix.setSaveOption(PtlPDFFixUp::SAVE_OPTION::SAVE_RECONSTRUCT);	//保存時のオプションを設定
		fix.setICCProfileCMYK(iccpcmyk);		//出力インテントのプロファイル（CMYK用）
		fix.setICCProfileRGB(iccprgb);			//出力インテントのプロファイル（RGB用）

		// PDF/Aへの変換
		bool bl = fix.fixUpPDFA(type, input);
		if (bl)
		{
			printf("%s への変換に成功しました。\n", desc.c_str());
		}
		else
		{
			printf("%s への変換に失敗しました。\n", desc.c_str());

			//変換エラーの内容を取得する
			PtlPDFFixUpErrors fxuperrs = fix.getErrors();
			int count = fxuperrs.getCount();
			printf("エラー数 ： %d\n",  count);
			for (int i = 0; i < count; i++)
			{
				PtlPDFFixUpError fxuperr = fxuperrs.get(i);
				fprintf(stderr, "%d\n : %s\n", fxuperr.getErrorCode(), fxuperr.getErrorMessageJP().c_str());
			}
		}

		// PDF文書を保存
		fix.save(output);
		printf("-- 完了 --\n");
	}
	catch (PtlException e)
	{
		fprintf(stderr, "Error code : %d\n %s\n", e.getErrorCode(), e.getErrorMessage().c_str());
		return 1;
	}
	return 0;
}
