从Adobe Reader的ActiveX控件获取PDF文档的页码

问题描述 投票:0回答:2

我成功使用Delph 7和Adobe Reader 7的ActiveX控件从ActiveX组件(TAcroPDF)中的打开的PDF文档中提取页码。我有兴趣升级到最新的Adobe阅读器,但在Adobe Reader 8(和9)中发生了一些变化,导致我无法升级(我没有测试过Adobe 10 / X)。使用Adobe 7,我使用Windows SDK函数EnumChildWindows来收集包含TAcroPDF组件的表单的子窗口,并找到名为AVPageNumView的控件,然后使用FindWindowEx来获取它的句柄。然后我调用SendMessage来获取具有页码信息的控件的文本。使用Adobe 8和9,窗口/控件AVPageNumView似乎不再存在。因此,我被困在Adobe 7中,仍在寻找获取页码的方法,最好是Adobe 9或10 / X.目标是不必用另一种技术进行完全重写,但如果它是唯一的解决方案,我对此持开放态度。

谢谢,迈克尔

delphi activex delphi-7 adobe-reader
2个回答
0
投票

你正在使用一个wndclass名称(AVPageNumView)。显然,新版本中的类名已更改。您可以使用类似WinDowse的东西来调查较新版本的Reader中的窗口,以找出新的类名。更新您的代码以首先检查旧的wndclass;如果找不到,请尝试找到新的。


0
投票
function EnumWindowProc(pHwnd: THandle; Edit: Integer): LongBool; stdcall;
    function GetWindowTxt(gwtHwnd: THandle): string;
    var dWTextBuf: PChar;
        TextLen: Integer;
    begin
      TextLen := SendMessage(gwtHwnd, WM_GetTextLength, 0, 0);;
      dWTextBuf := StrAlloc(TextLen + 1);
      SendMessage(gwtHwnd, WM_GetText, TextLen + 1, Integer(dWTextBuf));
      Result := dWTextBuf;
      StrDispose(dWTextBuf);
    end;

    function GetClassNameTxt(gcnHwnd: THandle): string;
    var dWClassBuf: PChar;
    begin
      dWClassBuf := StrAlloc(1024);
      GetClassName(gcnHwnd, dWClassBuf, 1024);
      Result := dWClassBuf;
      StrDispose(dWClassBuf);
    end;

begin
  Result := LongBool(True);
  if (GetClassNameTxt(pHwnd) = 'AVL_AVView') and (GetWindowTxt(pHwnd) = 'AVPageView') then
  begin
    TEdit(Edit).Text :=  GetWindowTxt(FindWindowEx(pHwnd, 0, 'RICHEDIT50W', nil));
    Result := LongBool(False);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  EnumChildWindows(AcroPDF1.Handle, @EnumWindowProc, LongInt(Edit1));
end;
© www.soinside.com 2019 - 2024. All rights reserved.