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

※以下は出力された List.TXT ファイルの一部。
******************************* Page = 1 *******************************
bc
Developing Applications Using Interapplication Communication
AdobeR AcrobatR SDK
******************************* Page = 2 *******************************
c 2006 Adobe Systems Incorporated. All rights reserved.
AdobeR AcrobatR SDK 8.0 Developing Applications Using Interapplication Communication for MicrosoftR WindowsR and Mac OSR
Edition 1.0, November 2006
If this guide is distributed with software that includes an end user agreement, this guide, as well as the software described in it, is furnished under license and may be used or copied only in accordance with the terms of such license.
補足
- 「隣接する文字列」の意味が分からなければ、
空白又は改行を区切りとする連続する文字列と考えて下さい。 - CreateWordHiliteメソッド、CreatePageHiliteメソッド、
CreateTextSelectionメソッドも参考にして下さい。
動作確認環境
- WindowsXP Pro(+ SP3) +
Acrobat 8.1.2 Pro + Office 2003 + MicrosoftUpdate
< 戻る >