Resize problem using AcroPDF in Delphi

拜拜、爱过 提交于 2020-01-06 04:27:09

问题


I successfully added AcroPDF in my application. When a PDF needs to be displayed I create an instance of AcroPDF dynamically and insert it into a TPanel with align set to alClient. My problem is that when the Form/Panel is resized the AcroPDF does not follow. Only if a new file is loaded. I tried several solutions to no avail. What should I do?


回答1:


It's a problem with recent versions of the Adobe OCX control, which you can work around by refocusing the control. In a preview dialog I have (which has an embedded, client-aligned AcroPdf control) I use the following OnResize handler for the form:

if Visible and (fPreviewV7 <> nil) then begin
  FocusControl(nil);
  FocusControl(fPreviewV7);
end;



回答2:


If you use ActiveX from version 9 of Acrobat Reader try this code in OnResize event of TPanel:

procedure TForm.PanelResize(Sender: TObject);
var
  rc: TRect;
  h: THandle;
begin
  if Assigned(AcroPdf) then
  begin
    if (Windows.GetClientRect(AcroPdf.Handle, rc)) then
    begin
      h := Windows.FindWindowEx(AcroPdf.Handle, 0, PChar('Static'), nil);
      if (h <> 0) then
        Windows.MoveWindow(h, 0, 0, rc.Right - rc.Left, rc.Bottom - rc.Top, True);
    end;
  end;
end;

The problem in that the child window of main AcroPdf window is not resized. So we found it by it's class name "Static" and manually move it to fill whole parent window. This code can not work on other versions of Acrobat Reader, because the window hierarchy and class name's may differ.



来源:https://stackoverflow.com/questions/4032988/resize-problem-using-acropdf-in-delphi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!