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

	概要：DeviceN Color

	Copyright 2025 Antenna House,Inc.
*/

#include < PdfTk.h >

using namespace std;
using namespace PdfTk;

int main(int argc, char* argv[])
{
	if (argc < 3) {
		printf("usage: DeviceNColor.exe in-pdf-file out-pdf-file \n");
		return 1;
	}

	try {
		PtlParamInput input(argv[1]);
		PtlParamOutput output(argv[2]);

		PtlPDFDocument doc;

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

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

		if (pages.isEmpty()) {
			printf("ページコンテナが空\n");
			return 1;
		}

		// 先頭ページの取得
		PtlPage page = pages.get(0);

		// ページコンテントの取得
		PtlContent& content = page.getContent();

		// DeviceNカラー
		PtlColorSpaceSeparation csSep1("SEP1", 0.7f, 0.8f, 1.0f, 0.9f);
		PtlColorSpaceSeparation csSep2("SEP2", 0.3f, 0.5f, 0.6f, 0.4f);
		PtlColorSpaceSeparation csSep3("SEP3", 0.4f, 0.3f, 0.5f, 0.2f);
		PtlColorSpaceSeparation csSep4("SEP4", 0.6f, 0.7f, 0.2f, 0.1f);
		PtlColorSpaceDeviceN csDeviceN(PtlColorSpaceDeviceN::COMP_Cyan | PtlColorSpaceDeviceN::COMP_Magenta | PtlColorSpaceDeviceN::COMP_Yellow | PtlColorSpaceDeviceN::COMP_Black, csSep1, csSep2, csSep3, csSep4);
		PtlColorDeviceN colorDeviceN(csDeviceN, 0.4f, 0.7f, 0.5f, 0.2f, 0.3f, 0.4f, 0.5f, 0.2f);

		PtlParamDrawShape shape;
		shape.setFillColor(colorDeviceN);
		shape.setLineColor(colorDeviceN);

		PtlRect rect(0.0f, 0.0f, 100.0f, 100.0f);
		//円形を描画
		content.drawCircle(rect, shape);

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

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

