VB6を使って、多数のPDFファイルの総ページ数とファイル名を取得して、csv形式で出力をしたいのですが、どのようにしたらよいのでしょうか?
Adobe Reader 7.0はインストールされています。
似たような質問があったのですが、よくわからずにいますので、ご指導よろしくお願い致します。
一年位前の古い記事ですが、こちらを参照してください:
http://madia.world.coocan.jp/vb/vb_bbs/200401_04010099.html
どうもAcrobatReaderだけでは、痒いところに手が届くようには出来ていない感じがします。
(Adobe Acrobat 7.0 Browser Control Type Library 1.0を使って、
PDFを表示することは出来てもそこから先が分かりませんでした)
風の噂ですが、PDFのバイナリフォーマットが公開されているようです。
もしかしたら、ファイル中に総ページ数が書いてあるかもしれませんね。
フォーマットを調べると2週間くらい英語漬けしなければいけない気がしてきました(orz
なのでウィンドウメッセージを使ってゴリゴリしてみたものを載せてみます。
※飽くまでも、「ゴリゴリすれば、こういう結果が得られる」というものであって推奨すべき物ではないです
…「出来るよ、でも汚いよ」というのが分かっていただければ幸いです(ぇ
動作保障はできません。
バグがあれば適宜デバッグしてください(orz
1 標準EXEを選択
2 Form1.frm, Module1.bas, tagWnd.cls を作成する
3 コードをそれぞれコピペする
4 [プロジェクト]-[コンポーネント]
-[Adobe Acrobat 7.0 Browser Control Type Library 1.0]
にチェックを入れる
5 メニュー:pGetPageCount を作る
5 AcroPDF:AcroPDF1 を Form1 に貼り付ける
6 実行する
7 メニュー:pGetPageCount を押す
→ 問題が無ければ、ページ数に関する何かが得られます
'---------------------------------Form1.frm
Option Explicit
Private Sub Form_Load()
AcroPDF1.LoadFile InputBox("PDFファイルパスを入力してください")
End Sub
Private Sub Form_Resize()
AcroPDF1.Move 0, 0, ScaleWidth, ScaleHeight
End Sub
Private Sub pGetPageCount_Click()
'ウィンドウを列挙していって、ページ数らしきウィンドウから(ゴニョゴニョ)
'AVPageNumViewの子、Editがページ数を表示しているウィンドウみたい(Spy++で甘めに確認)
Dim tWnd As New tagWnd
'自分の子を列挙していく
tWnd.Initialize Me.hWnd
'探す
Find_PageCount tWnd
End Sub
Private Sub Find_PageCount(ByVal Parent_tWnd As tagWnd)
'Parent_tWnd.CaptionがAVPageNumViewの子を検査する
Dim tWnd As tagWnd
Dim flg As Boolean
If Parent_tWnd.Caption = "AVPageNumView" Then
'これの子がPageCountを持っているはず
flg = True
End If
For Each tWnd In Parent_tWnd.Children
If flg Then
'PageCountを探す
If tWnd.Caption Like "*/*" Then
'PageCountだと思うので、表示する
Debug.Print "ページ:"; tWnd.Caption
End If
Else
'tWndを親として、検索する
Find_PageCount tWnd
End If
Next
End Sub
'---------------------------------Module1.bas
'created:2005/12/17 01:38
'module Module1
'*general*
Private Declare Function EnumChildWindows Lib "user32" _
(ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Children As Collection
'*public*
'EnumChildWindowsのコールバック関数
Public Function EnumChildProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
'子ウィンドウを追加
If hWnd <> lParam Then
'親ウィンドウ以外の子
Children.Add hWnd
End If
EnumChildProc = 1
End Function
Public Function ChildWindowCollection(ByVal hWnd As Long) As Collection
'子ウィンドウのコレクションを返す
Set Children = New Collection
EnumChildWindows hWnd, AddressOf EnumChildProc, hWnd
Set ChildWindowCollection = Children
End Function
'*End Of Code*
'---------------------------------tagWnd.cls
Option Explicit
'created:2005/12/17 01:31
'class tagWnd
'*general*
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_GETTEXTLENGTH = &HE
Private Const WM_GETTEXT = &HD
'!コードサイズを小さくするために、Publicスコープにしました
Public hWnd As Long
Public Caption As String
Public Children As Collection
'*public*
Public Sub Initialize(ByVal arg_hWnd As Long)
'初期化
Dim i As Long
Dim v As Variant
Dim buf() As Byte
Dim tWnd As tagWnd
Dim ChildrenhWnd As Collection
'arg_hWndウィンドウのキャプションを得る
hWnd = arg_hWnd
i = SendMessage(hWnd, WM_GETTEXTLENGTH, 0, ByVal 0) + 1
ReDim buf(1 To i)
SendMessage hWnd, WM_GETTEXT, i, buf(1)
Caption = Replace$(StrConv(buf, vbUnicode), vbNullChar, "")
'子のウィンドウハンドルを列挙し、初期化
Set Children = New Collection
For Each v In ChildWindowCollection(hWnd)
Set tWnd = New tagWnd
tWnd.Initialize v
Children.Add tWnd
Next
End Sub
'*End Of Code*
>ガッさん
丁寧な回答ありがとうございます(T_T)
早速やってみます。
| ツイート |
|