TOP > AcroExch.PDTextSelect > GetNumText [...]
説明
PDTextSelectオブジェクト上にあるテキスト選択状態のテキスト要素数を得ます。
※テキスト要素数 : 先に実行されたメソッド(CreateWordHilite、CreatePageHilite、CreateTextSelect)により、1文字単位か、単語又は隣接する文字列単位に変わります。そして配列として管理されます。 テキスト要素数とは、この時の配列の要素数(最大インデックス数)になります。
形式
long GetNumText();
引数
- 無し。
戻り値
- 選択された要素数。
何も無い時は0 が返る。
動作するバージョン
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
説明: PDFファイルの全テキストをテキストファイルに出力する。
- F8キーでステップ実行しながら動作確認する。
- 事前に参照設定をする。
001 Sub AcroExch_PDTextSelect_GetNumText()
002
003 Debug.Print "AcroExch_PDTextSelect_GetNumText:" & Now
004 Dim objAcroApp As New Acrobat.AcroApp
005 Dim objAcroHiliteList As New Acrobat.AcroHiliteList
006 Dim objAcroAVDoc As New Acrobat.AcroAVDoc
007 Dim objAcroPDDoc As Acrobat.AcroPDDoc
008 Dim objAcroPDPage As Acrobat.AcroPDPage
009 Dim objAcroPDTextSelect As Acrobat.AcroPDTextSelect
010 Dim objAcroAVPageView As Acrobat.AcroAVPageView
011 Dim lRet As Long
012 Dim lCnt As Long
013 Dim lPageCnt As Long
014 Dim i As Long
015 Dim j As Long
016 Dim strText As String
017 Dim lFileNo As Long
018 Dim lOutCnt As Long
019
020 'Acrobatを起動表示する
021 lRet = objAcroApp.Show '(TEST用)
022 'PDFドキュメントを開いて表示する。
023 lRet = objAcroAVDoc.Open("E:\Test01.pdf", "")
024 Set objAcroAVPageView = objAcroAVDoc.GetAVPageView()
025 Set objAcroPDDoc = objAcroAVDoc.GetPDDoc()
026 lPageCnt = objAcroPDDoc.GetNumPages - 1
027 Debug.Print "全頁数 = " & (lPageCnt + 1)
028 'ハイライトリストを作る。※「テキストのハイライト」では無い
029 lRet = objAcroHiliteList.Add(0, 32767)
030
031 '空きのファイル番号を取得
032 lFileNo = FreeFile
033 'テキストファイルをOPEN
034 Open "C:\List.txt" For Output As #lFileNo
035 lOutCnt = 0
036
037 For i = 0 To lPageCnt
038 lRet = objAcroAVPageView.Goto(i)
039 Set objAcroPDPage = objAcroAVPageView.GetPage()
040 '単語、又は隣接する文字列単位でHiliteListの範囲に従って
041 'PDTextSelectオブジェクトを作成する。
042 Set objAcroPDTextSelect = _
043 objAcroPDPage.CreateWordHilite(objAcroHiliteList)
044 'AcroPDTextSelectオブジェクトに従って、
045 '該当PDFページを選択状態にする。
046 lRet = objAcroAVDoc.SetTextSelection _
047 (objAcroPDTextSelect)
048 '選択状態した単語、又は隣接する文字列の数を取得する
049 lCnt = objAcroPDTextSelect.GetNumText() - 1
050 strText = ""
051 For j = 0 To lCnt
052 'Debug.Print objAcroPDTextSelect.GetText(j)
053 '単語、又は隣接する文字列単位で抽出する
054 '※空白文字は前の単語、又は隣接する文字列の最後となる
055 strText = strText & objAcroPDTextSelect.GetText(j)
056 If InStr(strText, vbCrLf) > 0 Then
057 '改行コードを含んだ単語
058 strText = Replace(strText, vbCrLf, "")
059 'ファイルに出力する
060 Print #lFileNo, strText
061 strText = ""
062 lOutCnt = lOutCnt + 1
063 End If
064 Next j
065 Next i
066
067 Debug.Print "出力行数 = " & lOutCnt
068 '出力テキストファイルを閉じる。
069 Close #lFileNo
070
071 'PDFファイルを保存しないで閉じる
072 lRet = objAcroAVDoc.Close(1)
073
074 'Acrobatを閉じる
075 lRet = objAcroApp.Hide
076 lRet = objAcroApp.Exit
077
078 'オブジェクトを強制解放する
079 Set objAcroHiliteList = Nothing
080 Set objAcroPDTextSelect = Nothing
081 Set objAcroAVPageView = Nothing
082 Set objAcroAVDoc = Nothing
083 Set objAcroPDPage = Nothing
084 Set objAcroPDDoc = Nothing
085 Set objAcroApp = Nothing
086
087 End Sub
Highlight:プログラミング言語のソースコードを構文で色分け (GUI編)
実行結果
TEST_PDTextSelect_GetNumText:2008/07/31 20:46:42
全頁数 = 34
出力行数 = 956
※下記は実行途中のPDFビュアーの画面の一部です。透明テキストがページ全体選択状態になっています。

補足
- 「隣接する文字列」の意味が分からなければ、
空白又は改行を区切りとする連続する文字列と考えて下さい。 - CreateWordHiliteメソッド、CreatePageHiliteメソッド、
CreateTextSelectionメソッドも参考にして下さい。
動作確認環境
- WindowsXP Pro(+ SP3) +
Acrobat 8.1.2 Pro + Office 2003 + MicrosoftUpdate
< 戻る >