/*
    Antenna House PDF Tool API V8.0
    Java Interface sample program

    概要：DeviceN Color

    Copyright 2025 Antenna House,Inc.
*/

package Sample;

import jp.co.antenna.ptl.*;

public class DeviceNColor {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        if (args.length < 2)
        {
            System.out.println("usage: java DeviceNColor in-pdf-file out-pdf-file");
            return;
        }

        try (PtlParamInput input = new PtlParamInput(args[0]);
             PtlParamOutput output = new PtlParamOutput(args[1]);
             PtlPDFDocument doc = new PtlPDFDocument())
        {
            // PDFファイルをロードします。
            doc.load(input);

            // PDFファイルをロードします。
            doc.load(input);

            try (PtlPages pages = doc.getPages())
            {
                // ページコンテナが空かどうか
                if (pages.isEmpty())
                {
                    System.out.println("ページコンテナが空");
                    return;
                }

                try (PtlPage page = pages.get(0);
                    PtlContent content = page.getContent())
                {
                    try (PtlParamDrawShape shape = new PtlParamDrawShape();
                        PtlColorSpaceSeparation csSep1 = new PtlColorSpaceSeparation("SEP1", 0.7f, 0.8f, 1.0f, 0.9f);
                        PtlColorSpaceSeparation csSep2 = new PtlColorSpaceSeparation("SEP2", 0.3f, 0.5f, 0.6f, 0.4f);
                        PtlColorSpaceSeparation csSep3 = new PtlColorSpaceSeparation("SEP3", 0.4f, 0.3f, 0.5f, 0.2f);
                        PtlColorSpaceSeparation csSep4 = new PtlColorSpaceSeparation("SEP4", 0.6f, 0.7f, 0.2f, 0.1f))
                    {
                        try (PtlColorSpaceDeviceN csDeviceN = new PtlColorSpaceDeviceN(PtlColorSpaceDeviceN.COMP_Cyan | PtlColorSpaceDeviceN.COMP_Magenta | PtlColorSpaceDeviceN.COMP_Yellow | PtlColorSpaceDeviceN.COMP_Black, csSep1, csSep2, csSep3, csSep4);
                            PtlColorDeviceN color = new PtlColorDeviceN(csDeviceN, 0.4f, 0.7f, 0.5f, 0.2f, 0.3f, 0.4f, 0.5f, 0.2f);
                            PtlRect rect = new PtlRect(0.0f, 0.0f, 100.0f, 100.0f))
                        {
                            shape.setFillColor(color);
                            shape.setLineColor(color);

                            //円形を描画
                            content.drawCircle(rect, shape);
                        }
                    }
                }
            }
            doc.save(output);
        }
        catch (PtlException pex) {
            System.out.println("PtlException : ErrorCode = " + pex.getErrorCode() + "\n  " + pex.getErrorMessage());
        }
        catch (Exception ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }
        catch (Error ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }
        finally {
            System.out.println("-- 完了 --");
        }
    }
}
