2,727
社区成员
发帖
与我相关
我的任务
分享
*VFP如何打开PDF文件并显示在表单中?(先安装Adobe Reader 5.0或6.0)
*---------------------------------------------------------------------------------------
*将下面程序代码保存为一个prg文件,传入PDF文件名作为参数即可。
Lparameters tFile
Public oform1
oform1=Newobject("form1")
If Vartype(cFile) # "U"
oForm1.cmdFile.Visible = .F.
oForm1.cmdExit.Visible = .F.
oForm1.oleControl1.Top = 12
oForm1.oleControl1.LoadFile([&cFile])
Endif
oform1.Show
*RETURN
**********************************************************
Define Class form1 As Form
DoCreate = .T.
Caption = "pdfForm"
Name = "Form1"
Add Object cmdfile As CommandButton With ;
Top = 12, ;
Left = 12, ;
Height = 27, ;
Width = 144, ;
Caption = "Select File", ;
Name = "cmdFile"
Add Object cmdexit As CommandButton With ;
Top = 12, ;
Left = 168, ;
Height = 27, ;
Width = 84, ;
Caption = "E\<xit", ;
Name = "cmdExit"
Add Object olecontrol1 As OleControl With ;
OLEClass = "PDF.PdfCtrl.6", ; &&如果是Adobe Reader 5.0,此处的6为5
Top = 48, ;
Left = 12, ;
Height = 192, ;
Width = 348, ;
Name = "Olecontrol1"
Procedure Init
Thisform.Resize()
Endproc
Procedure Resize
Thisform.Olecontrol1.Height = Thisform.Height - 60
Thisform.Olecontrol1.Width = Thisform.Width - 24
Thisform.Olecontrol1.Refresh()
Endproc
Procedure cmdfile.Click
Local cFile
cFile = Getfile([PDF])
If !Empty(cFile)
Thisform.oleControl1.LoadFile([&cFile])
Endif
Endproc
Procedure cmdexit.Click
Thisform.Release()
Endproc
Enddefine
*------------------------------------------------------------------
By:dkfdtf
新建一个表单,放一个按钮,按钮的 click 事件中写下面的代码(在机器安装了 Acrobat 9)
Thisform.Newobject('pdf', 'Olecontrol', '', '', 'AcroPDF.PDF.1')
Thisform.pdf.Move( 10, 10, Thisform.Width - 20, Thisform.Height - 20)
Thisform.pdf.SetShowToolbar(.f.)
Thisform.pdf.LoadFile( Getfile('pdf') )
Try
Thisform.pdf.Visible = .T.
Catch
Endtry
Thisform.pdf.SetFocus()
*------------------------------------------------------------------
By:dkfdtf
m.lSuccess = .T.
Try
* Adobe Reader 版本 7,8,9
Thisform.Newobject('pdf', 'Olecontrol', '', '', 'AcroPDF.PDF')
Catch
Try
* Adobe Reader 版本 6
Thisform.Newobject('pdf', 'Olecontrol', '', '', 'PDF.PdfCtrl.6')
Catch
Try
* Adobe Reader 版本 5
Thisform.Newobject('pdf', 'Olecontrol', '', '', 'PDF.PdfCtrl.5')
Catch
Messagebox('没有安装 Acrobat 或 Adobe Reader。', 16, '')
m.lSuccess = .F.
Endtry
Endtry
Endtry
If m.lSuccess
With Thisform.pdf
.LoadFile( Getfile('pdf') )
.Move( 10, 10, Thisform.Width - 20, Thisform.Height - 20)
.SetShowToolbar(.F.)
.Anchor = 15
Try
.Visible = .T.
Catch
Endtry
.SetFocus()
Endwith
Endif