Lazarus中文社区

 找回密码
 立即注册(注册审核可向QQ群索取)

QQ登录

只需一步,快速开始

Lazarus IDE and 组件 下载地址版权申明
查看: 2193|回复: 6

Lazarus打开PDF文件的例子

[复制链接]

该用户从未签到

发表于 2012-4-6 14:13:47 | 显示全部楼层 |阅读模式
  1. unit pdfopenform;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, EditBtn,
  6.   StdCtrls;
  7. type
  8.   { TForm1 }
  9.   TForm1 = class(TForm)
  10.     TProcessButton: TButton;
  11.     OpenURLButton: TButton;
  12.     OpenDocumentButton: TButton;
  13.     PDFChooser: TFileNameEdit;
  14.     Label1: TLabel;
  15.     procedure OpenDocumentButtonClick(Sender: TObject);
  16.     procedure OpenURLButtonClick(Sender: TObject);
  17.     procedure TProcessButtonClick(Sender: TObject);
  18.   private
  19.     { private declarations }
  20.   public
  21.     { public declarations }
  22.   end;
  23. var
  24.   Form1: TForm1;
  25. implementation
  26. uses process {for TProcess}, lclintf {for OpenDocument, OpenURL};
  27. {$R *.lfm}
  28. { TForm1 }
  29. procedure TForm1.TProcessButtonClick(Sender: TObject);
  30. var
  31.   AProcess: TProcess;
  32. begin
  33.   AProcess:=TProcess.Create(Nil);
  34.   try
  35.     // Executable & Parameters instead of CommandLine: no problems with quotes
  36.     AProcess.Executable:='explorer.exe';
  37.     AProcess.Parameters.Add(PDFChooser.FileName);
  38.     AProcess.Options := AProcess.Options + [poWaitOnExit];
  39.     AProcess.Execute;
  40.   finally
  41.     AProcess.Free;
  42.   end;
  43. end;
  44. procedure TForm1.OpenDocumentButtonClick(Sender: TObject);
  45. begin
  46.   //Opendocument opens a document with the default application associated with it in the system
  47.   if OpenDocument(PDFChooser.FileName)=false then ShowMessage('OpenDocument method failed.');
  48. end;
  49. procedure TForm1.OpenURLButtonClick(Sender: TObject);
  50. begin
  51.   // Opens a given URL with the default browser
  52.   // I wouldn't use this one because it's an extra redirection step and the user may not
  53.   // have a pdf plugin etc
  54.   if OpenURL('file://'+PDFChooser.FileName)=false then ShowMessage('OpenURL method failed.');
  55. end;
  56. end.
复制代码


完整项目代码下载
回复

使用道具 举报

该用户从未签到

发表于 2012-6-14 21:33:40 | 显示全部楼层
謝謝分享,加油一點
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2012-6-24 12:22:22 | 显示全部楼层
直接执行么?
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2012-7-15 01:38:41 | 显示全部楼层
其实就是普通打开 而已
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2012-10-1 12:46:26 | 显示全部楼层
阅读器呀,我喜欢
升级自己的程序中
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2012-10-1 13:13:43 | 显示全部楼层
我在测试时有问题呀???

AProcess.Executable:='explorer.exe';
pdfopenform.pas(49,14) Error: identifier idents no member "Executable"

AProcess.Parameters.Add(PDFChooser.FileName);
pdfopenform.pas(50,14) Error: identifier idents no member &quotarameters"
pdfopenform.pas(81) Fatal: There were 2 errors compiling module, stopping

我用的Lazarus版本是:0.9.30
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2012-10-1 17:03:55 | 显示全部楼层
我也终于搞定这个问题
如果编译出现我的问题,解决方法如下:
lazarus 的版本必须是1.0以上的
为了帮助大家学习,本人附下载连接如下:
ftp://newwiki.freepascal.org/pub ... -20120927-win32.exe

终于解决这个问题,再次感谢"飘飘的风"
回复 支持 反对

使用道具 举报

*滑块验证:

本版积分规则

QQ|手机版|小黑屋|Lazarus中国|Lazarus中文社区 ( 鄂ICP备16006501号-1 )

GMT+8, 2025-5-2 21:40 , Processed in 0.042830 second(s), 11 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表