/*
	Antenna House PDF Tool API V8.0
	Java Interface sample program

	概要：テキストボックス

	Copyright 2021-2025 Antenna House,Inc.
*/

package Sample;

import jp.co.antenna.ptl.*;

public class DrawTextBox_2 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        if (args.length < 1)
        {
            System.out.println("usage: java DrawTextBox_2 out-pdf-file");
            return;
        }

        try (PtlParamOutput outputFile = new PtlParamOutput(args[0]);
             PtlPDFDocument doc = new PtlPDFDocument();
             PtlOption option = new PtlOption())
        {
            option.setUnit(PtlOption.UNIT.UNIT_MM);


            String fontName = "メイリオ";
            float fontSize = 24.0f;

            try (PtlParamFont fontNormal = new PtlParamFont(fontName, fontSize, false, false, true);
                 PtlParamFont fontBoldItalic = new PtlParamFont(fontName, fontSize, true, true, true);
        		PtlPages pages = doc.getPages();
                PtlPage newpage = new PtlPage();	// 新しいページ
                PtlRect rectA4 = new PtlRect(0.0f, 0.0f, 297.0f, 210.0f);)		// A4横用紙
            {
        		newpage.setViewBox(rectA4);
        		//pages.append(newpage, PtlPages.INSERT_OPTION.OPTION_NONE);
        		pages.append(newpage, PtlPages.OPTION_NONE);
        		
        		PtlSize pageSize = newpage.getSize();
        		PtlContent content = newpage.getContent();
        		
                try (PtlRect rect1 = new PtlRect(10, 10, pageSize.getWidth() - 20, pageSize.getHeight() - 60);
            		 PtlTextBox textBox = content.drawTextBox(rect1, PtlContent.ALIGN.ALIGN_TOP_LEFT, pageSize.getWidth() - 30, pageSize.getHeight() - 70);
            		 PtlParamWriteStringTextBox paramWriteString = new PtlParamWriteStringTextBox();
                     PtlParamWriteStringTextBox paramWriteStringBoldItalic = new PtlParamWriteStringTextBox();)
                {

            		paramWriteString.setFont(fontNormal);

            		paramWriteString.setUnderline(true);
            		String text1 = ("下線はPtlParamWriteStringTextBoxで指定して書くことができます。");
            		textBox.writeStringNL(text1, paramWriteString);
            		paramWriteString.setUnderline(false);

            		textBox.writeNL();

            		paramWriteString.setStrikeOut(true);
            		String text2 = ("取り消し線はPtlParamWriteStringTextBoxで指定して書くことができます。");
            		textBox.writeStringNL(text2, paramWriteString);
            		paramWriteString.setStrikeOut(false);

            		textBox.writeNL();

            		paramWriteStringBoldItalic.setFont(fontBoldItalic);
            		String text3 = ("太字、斜体のフォントスタイルはPtlParamFontで設定します。");
            		textBox.writeStringNL(text3, paramWriteStringBoldItalic);
            		textBox.terminate();
                }
                	
                try (PtlColorDeviceRGB colorBack = new PtlColorDeviceRGB(1.0f, 0.8f, 0.8f);
            		PtlColorDeviceRGB colorRed = new PtlColorDeviceRGB(1.0f, 0.0f, 0.0f);
            		PtlRect rect2 = new PtlRect(130, 10, pageSize.getWidth() - 10, pageSize.getHeight() - 150);
            		PtlTextBox textBox2 = content.drawTextBox(rect2, PtlContent.ALIGN.ALIGN_TOP_LEFT, pageSize.getWidth() - 140, pageSize.getHeight() - 160);
            		PtlParamWriteStringTextBox paramWriteString = new PtlParamWriteStringTextBox();)
            	{
                		textBox2.setBackColor(colorBack);    // 背景色を設定
                		textBox2.setOutlineColor(colorRed);  // テキストボックスの縁取り色を設定
                		textBox2.setOpacity(0.6f);           // 不透明度を設定
                		textBox2.fitToBBox(false);           // TextBoxのサイズをテキストに合わせるかどうか(true:合わせる)

                		paramWriteString.setFont(fontNormal);

                		String text4 = ("枠で囲った文字列（背景色あり）は PtlTextBox に色を指定して書くことができます。");
                		textBox2.writeStringNL(text4, paramWriteString);

                		textBox2.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("-- 完了 --");
        }
	}
}

