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

	概要：PDFファイルの結合

	Copyright 2013-2021 Antenna House, Inc.
*/

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

using namespace PdfTk;

int main(int argc, char* argv[])
{
	if (argc < 4) {
		printf("usage: AppendPages.exe in-pdf-file out-pdf-file append-pdf-file\n");
		return 1;
	}
	try
	{
		PtlParamInput input(argv[1]);		//元PDF
		PtlParamOutput output(argv[2]);		//出力PDF
		PtlParamInput appendfile(argv[3]);	//追加PDF

		PtlPDFDocument doc;

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

		//ページコンテナの取得
		PtlPages& pages = doc.getPages();

		PtlPDFDocument doc_app;

		// 追加するPDFファイルをロードします。
		doc_app.load(appendfile);

		// ページの追加(1P目から全頁) OPTION_COPY_OUTLINES = 0x00000004 /* ページ挿入時にあわせてしおりをコピーします。他PDFのページ挿入時に有効となります。 */
		pages.append(doc_app, 0, PtlPages::PAGE_ALL, PtlPages::OPTION_COPY_OUTLINES);

		// 別のファイルに保存します。
		doc.save(output);

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

