/* Antenna House PDF Tool API V8.0 .NET Interface sample program 概要:テキストボックス:枠の線種設定 Copyright 2021-2025 Antenna House,Inc. */ using System; using PdfTkNet; namespace TextBoxOutlineStyle { class TextBoxOutlineStyle { static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("usage: TextBoxOutlineStyle.exe in-pdf-file out-pdf-file\n"); return; } try { using (PtlParamInput input = new PtlParamInput(args[0])) using (PtlParamOutput output = new PtlParamOutput(args[1])) using (PtlPDFDocument doc = new PtlPDFDocument()) using (PtlOption option = new PtlOption()) { option.setUnit(PtlOption.UNIT.UNIT_PT); doc.load(input); string fontName = "メイリオ"; float fontSize = 24.0f; using (PtlParamFont fontNormal = new PtlParamFont(fontName, fontSize, false, false, true)) using (PtlPages pages = doc.getPages()) using (PtlPage page = pages.get(0)) //1ページ目 using (PtlSize pageSize = page.getSize()) using (PtlContent content = page.getContent()) using (PtlRect rect = new PtlRect(80, 80, pageSize.getWidth() - 80, pageSize.getHeight() - 80)) using (PtlColorDeviceRGB colorBlack = new PtlColorDeviceRGB(0.0f, 0.0f, 0.0f)) using (PtlColorDeviceRGB colorRed = new PtlColorDeviceRGB(1.0f, 0.0f, 0.0f)) using (PtlColorDeviceRGB colorBlue = new PtlColorDeviceRGB(0.0f, 0.0f, 1.0f)) using (PtlColorDeviceRGB colorWite = new PtlColorDeviceRGB(1.0f, 1.0f, 1.0f)) using (PtlColorDeviceRGB colorYellow = new PtlColorDeviceRGB(1.0f, 1.0f, 0.0f)) { // 実線 using (PtlParamWriteStringTextBox paramWriteString = new PtlParamWriteStringTextBox()) using (PtlTextBox textBox = content.drawTextBox(rect, PtlContent.ALIGN.ALIGN_TOP_LEFT, 200, 200)) { // TextBoxの線スタイル textBox.setOutlineStyle(PtlTextBox.OUTLINE_STYLE.OUTLINE_STYLE_SOLID); // TextBoxの縁取りを付ける textBox.setOutlineColor(colorRed); // 縁取りがテキストを囲むサイズに変わるよう指定 textBox.fitToBBox(true); paramWriteString.setFont(fontNormal); paramWriteString.setTextColor(colorRed); string text = "実線赤・背景色なし(テキストを囲むサイズ)"; textBox.writeStringNL(text, paramWriteString); textBox.terminate(); } // 破線 using (PtlParamWriteStringTextBox paramWriteString = new PtlParamWriteStringTextBox()) using (PtlTextBox textBox = content.drawTextBox(rect, PtlContent.ALIGN.ALIGN_RIGHT, 200, 200)) { // TextBoxの線スタイル textBox.setOutlineStyle(PtlTextBox.OUTLINE_STYLE.OUTLINE_STYLE_DASHED); // TextBoxの縁取りを付ける textBox.setOutlineColor(colorBlue); // TextBoxの塗りつぶし色 textBox.setBackColor(colorWite); // 縁取りがテキストを囲むサイズに変わるよう指定 textBox.fitToBBox(false); paramWriteString.setFont(fontNormal); paramWriteString.setTextColor(colorBlack); string text = "破線青・背景色白"; textBox.writeStringNL(text, paramWriteString); textBox.terminate(); } // 縁取りなし using (PtlParamWriteStringTextBox paramWriteString = new PtlParamWriteStringTextBox()) using (PtlTextBox textBox = content.drawTextBox(rect, PtlContent.ALIGN.ALIGN_BOTTOM_LEFT, 200, 200)) { // TextBoxの塗りつぶし色 textBox.setBackColor(colorYellow); // 縁取りがテキストを囲むサイズに変わるよう指定 textBox.fitToBBox(true); paramWriteString.setFont(fontNormal); paramWriteString.setTextColor(colorBlack); string text = "縁取り線なし・背景色黄(テキストを囲むサイズ)"; textBox.writeStringNL(text, paramWriteString); textBox.terminate(); } doc.save(output); Console.WriteLine("-- 完了 --"); } } } catch (PtlException pex) { Console.WriteLine(pex.getErrorCode() + " : " + pex.getErrorMessageJP()); pex.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } }