TOP > AcroExch.PDPage > CreateWordHilite [...]
説明
単語、又は隣接する文字列単位の情報とそのリストをHiliteListオブジェクト情報の範囲に従って、1ページのテキスト選択であるAcroPDTextSelectオブジェクトを作成する。
形式
LPDISPATCH CreateWordHilite(LPDISPATCH iAcroHiliteList);
引数
- 第1引数(LPDISPATCH iAcroHiliteList) :
HiliteListオブジェクトは事前に範囲をAddメソッドで作成しておく。
戻り値
- Null以外 : 成功
- Null : 失敗
動作するバージョン
Version | Adobe Acrobat | 備考 |
---|---|---|
4 | - | Acrobat 4.0 ※Windows 98SE + Excel 2000 |
5 | - | Acrobat 5.0.5 |
6 | - | Acrobat 6.0.3 Pro |
7 | - | Acrobat 7.0.9 Pro Acrobat 7.1.4 Pro |
8 | OK | Acrobat 8.1.2 Pro |
9 | - | Acrobat 9.3.2 Extended |
10 | - | Acrobat X (10.1.8) Extended |
11 | - | Acrobat XI (11.0.04) Extended |
- OK = 動作する。
- NO = 動作しない。 戻り値が0を返す。
- - = 未確認。
サンプル:ExcelのVBA
説明:文字列を検索し、見つかったページの最初の単語、又は隣接する文字列で6文字目から10個をテキスト選択状態で画面表示する。
- F8キーでステップ実行しながら動作確認する。
- 事前に参照設定をする。
- テストする時は出来るだけテキストを沢山含んだページを対象にする。
001 Sub AcroExch_PDPage_CreateWordHilite()
002
003 '検索文字列
004 Const KensakuText As String = "agreement"
005
006 Dim objAcroApp As New Acrobat.AcroApp
007 Dim objAcroHiliteList As New Acrobat.AcroHiliteList
008 Dim objAcroAVDoc As New Acrobat.AcroAVDoc
009 Dim objAcroPDPage As Acrobat.AcroPDPage
010 Dim objAcroPDTextSelect As Acrobat.AcroPDTextSelect
011 Dim objAcroAVPageView As Acrobat.AcroAVPageView
012 Dim objAcroRect As Acrobat.AcroRect
013 Dim lRet As Long
014 Dim lCnt As Long
015 Dim j As Long
016 Dim strText As String
017
018 'Acrobatを起動表示する
019 lRet = objAcroApp.Show '(注1)
020 'PDFドキュメントを開いて表示する。
021 lRet = objAcroAVDoc.Open("E:\Test01.pdf", "")
022 'PDFドキュメントの先頭ページから文字列検索する。
023 ' 第2引数:大文字小文字の区別無し
024 ' 第3引数:単語単位の検索無し
025 ' 第4引数:最初のページから検索する
026 lRet = objAcroAVDoc.FindText _
027 (KensakuText, False, False, True)
028 If lRet = False Then
029 '検索出来なかった
030 Debug.Print "Not Found =(" & KensakuText & ")"
031 GoTo Skip:
032 End If
033 'ハイライトリストを作る。※「テキストのハイライト」では無い
034 lRet = objAcroHiliteList.Add(5, 10)
035
036 '検索して見つかったページのAVPageViewオブジェクトを作成
037 Set objAcroAVPageView = objAcroAVDoc.GetAVPageView()
038 '検索して見つかったページのPDPageオブジェクトを作成
039 Set objAcroPDPage = objAcroAVPageView.GetPage()
040
041 '1文字単位で文字をHiliteListの範囲に従って
042 'PDTextSelectオブジェクトを作成する。
043 'Set objAcroPDTextSelect = _
044 objAcroPDPage.CreatePageHilite (objAcroHiliteList)
045 '単語、又は隣接する文字列単位でHiliteListの範囲に従って
046 'PDTextSelectオブジェクトを作成する。
047 Set objAcroPDTextSelect = _
048 objAcroPDPage.CreateWordHilite(objAcroHiliteList)
049
050 'AcroPDTextSelectオブジェクトに従って、
051 '該当PDFページを選択状態にする。
052 lRet = objAcroAVDoc.SetTextSelection(objAcroPDTextSelect)
053 '抽出した文字列の数(Index)を取得する
054 lCnt = objAcroPDTextSelect.GetNumText() - 1
055 strText = ""
056 For j = 0 To lCnt
057 Debug.Print objAcroPDTextSelect.GetText(j)
058 '単語単位で抽出する
059 strText = strText & objAcroPDTextSelect.GetText(j)
060 Next j
061 Debug.Print ""
062 Debug.Print strText
063 Debug.Print ""
064 '選択状態になっている四方範囲(AcroRect)を取得する。
065 Set objAcroRect = objAcroPDTextSelect.GetBoundingRect
066 With objAcroRect
067 Debug.Print "Rect.Top=" & .Top
068 Debug.Print "Rect.bottom=" & .bottom
069 Debug.Print "Rect.Left=" & .Left
070 Debug.Print "Rect.Right=" & .Right
071 End With
072 Debug.Print ""
073
074 Skip:
075 'PDFファイルを保存しないで閉じる
076 lRet = objAcroAVDoc.Close(1)
077
078 'Acrobatを閉じる
079 lRet = objAcroApp.Hide '(注1)
080 lRet = objAcroApp.Exit '(注1)
081
082 'オブジェクトを強制解放する
083 Set objAcroHiliteList = Nothing
084 Set objAcroPDPage = Nothing
085 Set objAcroPDTextSelect = Nothing
086 Set objAcroAVPageView = Nothing
087 Set objAcroRect = Nothing
088 Set objAcroAVDoc = Nothing
089
090 End Sub
Highlight:プログラミング言語のソースコードを構文で色分け (GUI編)
実行結果
※以下はイミディエイト画面の内容
All
rights
reserved.
Adobe
R
Acrobat
R
SDK
8.0
Developing
All rights reserved.
AdobeR AcrobatR SDK 8.0 Developing
Rect.Top=751
Rect.bottom=724
Rect.Left=36
Rect.Right=245
サンプルの内容、及び結果の解説
- AcroRect情報はそこを選択すると画面の様になる。
- 以下は実行中のテキスト選択中の画面。
- CreatePageHilite メソッドをコメントにしてあるが、コメントを外して実行結果を比べてみると理解しやすい。
補足
- F8キーでステップ実行し、各メソッドによりどのような動きをするかよく観察すること。
- (注1)はテスト用のロジック。
動作確認環境
- WindowsXP Pro(+ SP3) +
Acrobat 8.1.2 Pro + Office 2003 + MicrosoftUpdate
< 戻る >