/*
	Antenna House PDF Tool API V8.0
	Java Interface sample program

	概要：行間を広くした文字列・文字間隔をかえた文字列

	Copyright 2025- Antenna House,Inc.
*/

package Sample;

import jp.co.antenna.ptl.*;

public class DrawTextBox_5 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        if (args.length < 2)
        {
            System.out.println("usage: java DrawTextBox_5 in-pdf-file out-pdf-file");
            return;
        }

        try (PtlParamInput inputFile = new PtlParamInput(args[0]);
             PtlParamOutput outputFile = new PtlParamOutput(args[1]);
             PtlPDFDocument doc = new PtlPDFDocument();)
        {
            doc.load(inputFile);

            try (PtlPages pages = doc.getPages();
                    PtlPage page = pages.get(0);     //1ページ目
                    PtlSize pageSize = page.getSize();
                    PtlContent content = page.getContent();
                    PtlColorDeviceRGB colorRed = new PtlColorDeviceRGB(1.0f, 0.0f, 0.0f);
            		PtlParamFont fontNormal = new PtlParamFont("メイリオ", 18.0f, false, false, true);
            		PtlRect rect = new PtlRect(10, 10, pageSize.getWidth() - 10, pageSize.getHeight() - 10);
            		PtlTextBox textBox = content.drawTextBox(rect, PtlContent.ALIGN.ALIGN_TOP_LEFT, pageSize.getWidth() - 20, pageSize.getHeight() - 20))
           {
	            // TextBoxの縁取りを付ける
	            textBox.setOutlineColor(colorRed);
	
	            try (PtlParamWriteStringTextBox paramWriteString = new PtlParamWriteStringTextBox();)
               {
	                paramWriteString.setFont(fontNormal);
	        	
	                String text50 = ("通常文字。");
	                textBox.writeStringNL(text50, paramWriteString);
	                String text51 = ("「これは、私が小さいときに、村の茂平というおじいさんからきいたお話です。むかしは、私たちの村のちかくの、中山というところに小さなお城があって、中山さまというおとのさまが、おられたそうです。その中山から、少しはなれた山の中に、「ごん狐」という狐がいました。」（新美南吉「ごん狐」）");
	                textBox.writeStringNL(text51, paramWriteString);
	                textBox.writeNL();
	
	                paramWriteString.setLineSpacing(1.5f);
	                String text60 = ("行間を広くします。");
	                textBox.writeStringNL(text60, paramWriteString);
	                String text61 = ("「これは、私が小さいときに、村の茂平というおじいさんからきいたお話です。むかしは、私たちの村のちかくの、中山というところに小さなお城があって、中山さまというおとのさまが、おられたそうです。その中山から、少しはなれた山の中に、「ごん狐」という狐がいました。」（新美南吉「ごん狐」）");
	                textBox.writeStringNL(text61, paramWriteString);
	                textBox.writeNL();
	
	                paramWriteString.setLineSpacing(1.0f);
	                String text40 = ("行間を狭くします。");
	                textBox.writeStringNL(text40, paramWriteString);
	                String text41 = ("「これは、私が小さいときに、村の茂平というおじいさんからきいたお話です。むかしは、私たちの村のちかくの、中山というところに小さなお城があって、中山さまというおとのさまが、おられたそうです。その中山から、少しはなれた山の中に、「ごん狐」という狐がいました。」（新美南吉「ごん狐」）");
	                textBox.writeStringNL(text41, paramWriteString);
	
	                textBox.writeNL();
	
	                String text7 = ("文字間隔をかえてみます。");
	                textBox.writeStringNL(text7, paramWriteString);
	
	                String text72 = ("文字間隔狭い(-1)。");
	                paramWriteString.setCharSpacing(-1);
	                textBox.writeStringNL(text72, paramWriteString);
	
	                String text73 = ("文字間隔広い(1)。");
	                paramWriteString.setCharSpacing(1);
	                textBox.writeStringNL(text73, paramWriteString);
	
	                String text74 = ("文字間隔広い(2)。");
	                paramWriteString.setCharSpacing(2);
	                textBox.writeStringNL(text74, paramWriteString);
               }
	            textBox.terminate();
	
	            doc.save(outputFile);
            }
        }
        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("-- 完了 --");
        }
	}
}

