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

	概要：開き方の取得

	Copyright 2013-2021 Antenna House, Inc.
*/

#include < PdfTk.h >
#include < stdio.h >

using namespace PdfTk;

int main(int argc, char* argv[])
{
	if (argc < 2) {
		printf("usage: GetDocInfo.exe in-pdf-file\n");
		return 1;
	}
	try
	{
		PtlParamInput input(argv[1]);
		PtlPDFDocument doc;

		// PDFファイルをロードします。
		doc.load(input);

		//PDFの文書プロパティ
		PtlDocProperty& docproperty = doc.getDocProperty();

		//PDFの文書情報
		PtlDocInfo& docinf = docproperty.getDocInfo();

		//タイトル取得
		PtlParamString title = docinf.getTitle();
		printf("Title : %s\n", title.c_str());

		//著者取得
		PtlParamString author = docinf.getAuthor();
		printf("Author : %s\n", author.c_str());

		//サブジェクト取得
		PtlParamString subject = docinf.getSubject();
		printf("Subject : %s\n", subject.c_str());

		//キーワード取得
		PtlParamString keywords = docinf.getKeywords();
		printf("Keywords : %s\n", keywords.c_str());

		//クリエータ取得
		PtlParamString creator = docinf.getCreator();
		printf("Creator : %s\n", creator.c_str());

		//プロデューサ取得
		PtlParamString producer = docinf.getProducer();
		printf("Producer : %s\n", producer.c_str());

		//作成日付を取得
		PtlDate creationDate = docinf.getCreationDate();
		printf("CreationDate : %d/%d/%d %d:%d:%d\n"
			, creationDate.getYear()
			, creationDate.getMonth()
			, creationDate.getDay()
			, creationDate.getHour()
			, creationDate.getMin()
			, creationDate.getSec());

		//更新日付を取得
		PtlDate modDate = docinf.getModDate();
		printf("ModDate : %d/%d/%d %d:%d:%d\n"
			, modDate.getYear()
			, modDate.getMonth()
			, modDate.getDay()
			, modDate.getHour()
			, modDate.getMin()
			, modDate.getSec());

		printf("完了!\n");
	}
	catch (const PtlException &e)
	{
		fprintf(stderr, "Error code : %d\n %s\n", e.getErrorCode(), e.getErrorMessage().c_str());
	}	
	return 0;
}

