activePDF Toolkit 2011 API リファレンス
GetTextWidth
テクニカル リファレンス > Toolkit オブジェクト > Toolkit メソッド > GetTextWidth

Glossary Item Box

説明: SetFont メソッドで指定したフォント情報に基づいた文字列のテキスト幅を取得します。
戻り値: 値の型 説明 & 設定
Float 文字列のテキスト幅
構文: object.GetTextWidth TextString, PageNr
引数: 引数 値の型 説明 & 設定
object N/A オブジェクトのインスタンスを設定します。
TextString String 指定する文字列
PageNr Long オプション

0 = 新規または現在開いているページで動作(デフォルト)

>1 = 指定したページで動作

-1 = すべてのページで動作
例:
'GetTextWidth Example
Set TK = CreateObject("APToolkit.Object")

r = TK.OpenOutputFile("GetTextWidth.pdf")

'Set the font for the printed text
TK.SetFont "Helvetica", 20, 0

'Get the width of the text so that it can be centered on the page
strText = "Hello World"
strTextWidth = TK.GetTextWidth(strText)

'Print the text centered
strPageWidth = 612 '8.5" (72 = 1")
strLLX = (strPageWidth - strTextWidth) / 2
strLLY = 740
TK.PrintText strLLX, strLLY, strText, 0

TK.CloseOutputFile
Set TK = Nothing