Delphi XE8 加载 PDF 文件

Delphi XE8 Load PDF File

我想知道怎么做:

  1. 单击按钮,从目录打开 PDF 文件。

  2. 在表单上查看 PDF 文件。

要嵌入 PDF,首先想到的两个想法是

1) 搜索支持 PDF 的 COM 对象 - 快速搜索产生了这个:http://www.biopdf.com/guide/com_interface.php,但似乎还有其他对象。

2) 最坏的情况是您可以嵌入一个包含 HTML 代码的 Web 面板:

<object data="test.pdf" type="application/pdf" width="500" height="300"> alt : <a href="test.pdf">test.pdf</a> </object>

您不需要像现在这样跳来跳去。 Windows 将为您找到与 PDF 文件关联的应用程序。

procedure TForm1.Button1Click(Sender: TObject);
var
  s: String;     
  Ret: DWord;
begin
  s := 'C:\MyFiles\MyFile.pdf';
  Ret := ShellExecute(Handle, nil, PChar(s), nil, nil, SW_SHOW);
  if Ret < 32 then
    ShowMessage(SysErrorMessage(GetLastError));
end;

注意:通常您应该永远不要调用 WinAPI 函数而不检查 return 值。在这种情况下,您会知道它是否不起作用,因为 PDF 无法打开。

感谢您的回答,但我最终得到了它(现在已经有几年没有使用 Delphi,忘记了用途)。

情况是这样的:"On a button click, open a PDF file from a directory."

uses shellApi;

procedure TForm1.Button1Click(Sender: TObject);

begin
ShellExecute(Handle, 'open', 'C:\pathwaytopdf.pdf', nil, nil, SW_SHOWNORMAL);
end;
end.

感谢您的回答。