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メソッドのサンプルとほぼ同じです。
Sub AcroExch_PDTextSelect_GetPage()
Debug.Print "AcroExch_PDTextSelect_GetPage:" & Now
Const CON_ASTA = "*******************************"
Dim objAcroApp As New Acrobat.AcroApp
Dim objAcroHiliteList As New Acrobat.AcroHiliteList
Dim objAcroAVDoc As New Acrobat.AcroAVDoc
Dim objAcroPDDoc As Acrobat.AcroPDDoc
Dim objAcroPDPage As Acrobat.AcroPDPage
Dim objAcroPDTextSelect As Acrobat.AcroPDTextSelect
Dim objAcroAVPageView As Acrobat.AcroAVPageView
Dim lRet As Long
Dim lCnt As Long
Dim lPageCnt As Long
Dim i As Long
Dim j As Long
Dim strText As String
Dim lFileNo As Long
Dim lOutCnt As Long
'Acrobatを起動表示する
lRet = objAcroApp.Show '(TEST用)
'PDFドキュメントを開いて表示する。
lRet = objAcroAVDoc.Open("E:¥Test01.pdf", "")
Set objAcroAVPageView = objAcroAVDoc.GetAVPageView()
Set objAcroPDDoc = objAcroAVDoc.GetPDDoc()
lPageCnt = objAcroPDDoc.GetNumPages - 1
Debug.Print "全頁数 = " & (lPageCnt + 1)
'ハイライトリストを作る。※「テキストのハイライト」では無い
lRet = objAcroHiliteList.Add(0, 32767)
'空きのファイル番号を取得
lFileNo = FreeFile
'テキストファイルをOPEN
Open "C:¥List.txt" For Output As #lFileNo
lOutCnt = 0
For i = 0 To lPageCnt
lRet = objAcroAVPageView.Goto(i)
Set objAcroPDPage = objAcroAVPageView.GetPage()
'単語、又は隣接する文字列単位でHiliteListの範囲に従って
'PDTextSelectオブジェクトを作成する。
Set objAcroPDTextSelect = _
objAcroPDPage.CreateWordHilite(objAcroHiliteList)
'AcroPDTextSelectオブジェクトに従って、
'該当PDFページを選択状態にする。
lRet = objAcroAVDoc.SetTextSelection _
(objAcroPDTextSelect)
'選択状態した単語、又は隣接する文字列の数を取得する
lCnt = objAcroPDTextSelect.GetNumText() - 1
strText = ""
Print #lFileNo, CON_ASTA & " Page = " & _
(objAcroPDTextSelect.GetPage() + 1) & " " & CON_ASTA
For j = 0 To lCnt
'単語、又は隣接する文字列単位で抽出する
'※空白文字は前の単語、又は隣接する文字列の最後となる
strText = strText & objAcroPDTextSelect.GetText(j)
If InStr(strText, vbCrLf) > 0 Then
'改行コードを含んだ単語
strText = Replace(strText, vbCrLf, "")
'ファイルに出力する
Print #lFileNo, strText
strText = ""
lOutCnt = lOutCnt + 1
End If
Next j
Next i
Debug.Print "出力行数 = " & lOutCnt
'出力テキストファイルを閉じる。
Close #lFileNo
'PDFファイルを保存しないで閉じる
lRet = objAcroAVDoc.Close(1)
'Acrobatを閉じる
lRet = objAcroApp.Hide
lRet = objAcroApp.Exit
'オブジェクトを強制解放する
Set objAcroHiliteList = Nothing
Set objAcroPDTextSelect = Nothing
Set objAcroAVPageView = Nothing
Set objAcroAVDoc = Nothing
Set objAcroPDPage = Nothing
Set objAcroPDDoc = Nothing
Set objAcroApp = Nothing
End Sub
実行結果
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
< 戻る >