紧急,如何读取PDF文件!(50分)

  • 主题发起人 主题发起人 由由(love)
  • 开始时间 开始时间

由由(love)

Unregistered / Unconfirmed
GUEST, unregistred user!
我把PDF文件存放在WEB服务器上,现在想在客户端打开这个PDF文件,该怎么办?
其实我是在WEB页面上做的一个OCX文件,从数据库中取出PDF文件名,然后双单可以打开客户端的PDF文件阅读器并打开这个PDF文件,怎么解决?急,多谢!12:00结贴!
 
客户端需要安装Adobe Reader,然后直接做连接就可以了,IE能打开,不用OCX
 
我已经用OCX文件做了其它的一些功能,所以不能改了!只有在用OCX文件调用客户端的PDF阅读器来打开了,该怎么写呢?
我知道WORD的可以这么写,那PDF又该如何呢?

word := CreateOleObject('Word.Application');
Word.Visible := True;
word.Documents.open(S_Url,ReadOnly:=true)

请高手帮助,急需!!!
 
用OCX也没关系,我的意思是如果客户端装了Reader后直接用超文本连接就可以了
http://server/document.pdf
 
有一个VB的程序也是读取PDF数据的其中的代码如下
我没弄懂,用DELPHI该怎么写?Const HKEY_CURRENT_USER = &H80000001
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Private Declare Function RegQueryInfoKey Lib "advapi32.dll" Alias "RegQueryInfoKeyA" (ByVal hKey As Long, ByVal lpClass As String, lpcClass As Long, ByVal lpReserved As Long, lpcSubKeys As Long, lpcMaxSubKeyLen As Long, lpcMaxClassLen As Long, lpcValues As Long, lpcMaxValueNameLen As Long, lpcMaxValueLen As Long, lpcbSecurityDescriptor As Long, lpftLastWriteTime As Long) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcValueName As Long, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Const ChunkSize As Integer = 16384
'用api函数读取
Private Sub GetMailList_Click()
On Error GoTo quit

Dim lResult, lRootKey, lKey As Long
Dim lSubKeys As Long
Dim lValues As Long
Dim KeyName As String
Dim lKeyNameSize, lTempKeyNameSize As Long
Dim KeyValue As String
Dim lKeyValueSize, lTempKeyValueSize As Long
Dim i As Integer
Dim OEStorePath As String
Dim UserProfile As String
Dim fso As New FileSystemObject

lResult = RegOpenKey(HKEY_CURRENT_USER, "Identities", lRootKey)

If lResult = 0 Then
lResult = RegQueryInfoKey(lRootKey, 0&, 0&, 0&, 0&, 0&, 0&, lValues, lKeyNameSize, lKeyValueSize, 0&, 0&)

If lResult = 0 Then
For i = 0 To lValues - 1
lTempKeyNameSize = lKeyNameSize + 1
KeyName = String(lKeyNameSize + 1, " ")
lTempKeyValueSize = lKeyValueSize + 1
KeyValue = String(lKeyValueSize + 1, " ")

lResult = RegEnumValue(lRootKey, i, KeyName, lTempKeyNameSize, 0&, 0&, KeyValue, lTempKeyValueSize)

' trim the null at the end of the returned value
If InStr(KeyName, "Default User ID") > 0 Then
Exit For
End If
Next i
End If

lResult = RegOpenKey(lRootKey, Left$(KeyValue, lTempKeyValueSize - 1) + "/Software/Microsoft/Outlook Express/5.0", lKey)
lResult = RegQueryInfoKey(lKey, 0&, 0&, 0&, 0&, 0&, 0&, lValues, lKeyNameSize, lKeyValueSize, 0&, 0&)

If lResult = 0 Then
For i = 0 To lValues - 1
lTempKeyNameSize = lKeyNameSize + 1
KeyName = String(lKeyNameSize + 1, " ")
lTempKeyValueSize = lKeyValueSize + 1
KeyValue = String(lKeyValueSize + 1, " ")

lResult = RegEnumValue(lKey, i, KeyName, lTempKeyNameSize, 0&, 0&, KeyValue, lTempKeyValueSize)

' trim the null at the end of the returned value
If Left$(KeyName, lTempKeyNameSize) = "Store Root" Then
OEStorePath = Left$(KeyValue, lTempKeyValueSize - 1)
Exit For
End If
Next i
End If
End If


If Left$(OEStorePath, 1) = "%" Then
UserProfile = Environ("UserProfile")
OEStorePath = UserProfile + Mid$(OEStorePath, 14)
End If

If Right$(OEStorePath, 1) = "/" Then
fso.CopyFile OEStorePath + "收件箱.dbx", App.Path + "/收件箱.dbx"
Else
fso.CopyFile OEStorePath + "/收件箱.dbx", App.Path + "/收件箱.dbx"
End If

If fso.FileExists(App.Path + "/maillist.ini") Then
fso.DeleteFile App.Path + "/maillist.ini"
End If

'get pdf list
Shell App.Path + "/GetPDF.exe 收件箱.dbx", vbHide

Progress.Show vbModal

quit:
End Sub

Private Sub Submit_Click()
Dim i, j, k As Integer
Dim sTemp As String
Dim avDoc As Variant
Dim formApp As Variant
Dim acroForm As Variant
Dim fld As Variant
Dim FileNumber As Integer
Dim InBuf As String
Dim info() As String
Dim formName() As String
Dim FormNumber As Integer
Dim DBName() As String
Dim TempFormName As String
Dim TempDBName() As String
Dim sSQL As String
Dim ws As rdoEnvironment
Dim db As rdoConnection
Dim rs As rdoResultset
Dim TableDefs As rdoTable
Dim FieldDefs As Variant
Dim DataFile As Integer, Fl As Long, Chunks As Integer
Dim Fragment As Integer, Chunk() As Byte

'Set the mouse icon to display an hourglass


Dim Item As MSComctlLib.ListItem



i = 0
For Each Item In MailList.ListItems
If Item.Checked Then
i = i + 1
End If
Next
If i > 0 Then 'if have mailitem checked
Screen.MousePointer = 11
StoreDBProgress.Show
StoreDBProgress.DBProgressBar.Max = i

i = 0
For Each Item In MailList.ListItems

If Item.Checked Then

i = i + 1
StoreDBProgress.DBProgressBar.Value = i

FileNumber = FreeFile

'Get all keywords from type file
j = 0
Open App.Path + "/" + PDFList(Item.Index - 1) + ".type" For Input As FileNumber
Do While Not EOF(FileNumber)
Line Input #FileNumber, InBuf

InBuf = Trim(InBuf)
If InBuf <> "" Then
info = Split(InBuf, " -> ")

If info(0) = "√" Then
ReDim Preserve formName(j + 1)
ReDim Preserve DBName(j + 1)
formName(j) = info(1)
DBName(j) = info(2)
j = j + 1
End If
End If
Loop

Close #FileNumber

If j = 0 Then
MsgBox "注意,该PDF文件没有定义关键字,请重新定义!", vbExclamation, "注意"
Exit Sub
End If

'Open the PDF file

Set avDoc = CreateObject("AcroExch.AVDoc")
bOK = avDoc.Open(App.Path + "/Workspace/" + Item.SubItems(4), "")

'If everything was OK opening the PDF, we now instantiate the Forms
'Automation object.
If bOK Then
Set formApp = CreateObject("AFormAut.App")
Set acroForm = formApp.Fields
Else
Set avDoc = Nothing
MsgBox "打开PDF文件失败!", vbExclamation, "注意"
GoTo quit
End If

'Check if this pdf exists enough keywords
'FormNumber = 0
'For Each fld In acroForm
' For k = 0 To j - 1
' If fld.Name = formName(k) Then
' FormNumber = FormNumber + 1
' End If
' Next k
'Next

'It means this pdf file have enough keywords
'If FormNumber >= j Then
info = Split(DBName(j - 1), ".")
Set ws = rdoEngine.rdoEnvironments(0)
Set db = ws.OpenConnection(info(0))


Set rs = db.OpenResultset("select count(*) from " + info(1) + " where pdfname='" + Item.SubItems(4) + "'")

'MsgBox rs.rdoColumns(0).Value

If rs.rdoColumns(0).Value = 0 Then
'insert
info = Split(DBName(j - 1), ".")


'MsgBox "insert into " + Info(1) + "(pdfname) values('" + Item.SubItems(4) + "')"
'insert
db.Execute ("insert into " + info(1) + "(pdfname) values('" + Item.SubItems(4) + "')")

End If

'update

Open App.Path + "/" + PDFList(Item.Index - 1) + ".type" For Input As FileNumber
Do While Not EOF(FileNumber)
Line Input #FileNumber, InBuf

InBuf = Trim(InBuf)
If InBuf <> "" Then
info = Split(InBuf, " -> ")

If info(0) <> "√" And info(0) <> "[PDF文件名]" And info(0) <> "[PDF文件本身]" Then

TempFormName = info(0)
TempDBName = Split(info(1), ".")

sSQL = "update " + TempDBName(1) + " set " + TempDBName(2) + "="

Dim bExists As Boolean
bExists = False
For Each fld In acroForm
If fld.Name = TempFormName Then
bExists = True

'check its type
For Each TableDefs In db.rdoTables
If TempDBName(1) = TableDefs.Name Then
For Each FieldDefs In TableDefs.rdoColumns
If FieldDefs.Name = TempDBName(2) Then
'char
If FieldDefs.Type = rdTypeCHAR Or FieldDefs.Type = rdTypeVARCHAR Then
sSQL = sSQL + "'" + fld.Value + "' where pdfname='" + Item.SubItems(4) + "'"
Else 'number
If Len(fld.Value) <> 0 Then
sSQL = sSQL + fld.Value + " where pdfname='" + Item.SubItems(4) + "'"
Else
sSQL = sSQL + "0 where pdfname='" + Item.SubItems(4) + "'"
End If
End If

'exit loop
Exit For
End If
Next FieldDefs

'exit loop
Exit For
End If
Next TableDefs

'exit loop
Exit For
End If
Next

If Not bExists Then
sSQL = sSQL + "'无'"
End If

'MsgBox sSQL
'update
db.Execute (sSQL)

End If
End If
Loop

Close #FileNumber

'close the resultset
rs.Close

'process pdf filename and pdf
Open App.Path + "/" + PDFList(Item.Index - 1) + ".type" For Input As FileNumber
Do While Not EOF(FileNumber)
Line Input #FileNumber, InBuf

InBuf = Trim(InBuf)
If InBuf <> "" Then
info = Split(InBuf, " -> ")

If info(0) = "[PDF文件本身]" Then
TempDBName = Split(info(1), ".")

'the result of query
Set rs = db.OpenResultset("select * from " + TempDBName(1) + " where pdfname='" + Item.SubItems(4) + "'", rdOpenKeyset, rdConcurRowVer)

If rs.RowCount <> 0 Then
rs.Edit
DataFile = 100
Open App.Path + "/Workspace/" + Item.SubItems(4) For Binary Access Read As DataFile
Fl = LOF(DataFile) ' Length of data in file
If Fl = 0 Then Close DataFile: Exit Do
Chunks = Fl / ChunkSize
Fragment = Fl Mod ChunkSize
rs.rdoColumns(TempDBName(2)).AppendChunk Null
ReDim Chunk(Fragment)
Get DataFile, , Chunk()
rs.rdoColumns(TempDBName(2)).AppendChunk Chunk()
ReDim Chunk(ChunkSize)
For k = 1 To Chunks
Get DataFile, , Chunk()
rs.rdoColumns(TempDBName(2)).AppendChunk Chunk()
Next k
Close DataFile
rs.Update
End If

'exit loop
Exit Do
End If
End If
Loop

db.Close
ws.Close

'End If

Set avDoc = Nothing

End If
Next

Screen.MousePointer = 4
Unload StoreDBProgress
MsgBox "注意,PDF文件入库结束!", vbInformation, "注意"
End If
GoTo Ok

quit:

MsgBox "注意,入库过程出现错误,请修改文档的内容!", vbExclamation, "注意"
Screen.MousePointer = 4
Unload StoreDBProgress

Ok:

End Sub




 
Adobe Reader很多地方都有下载的
你去google搜一下
www.skycn.net上肯定有
 
adobe acrobat
 
没错,关键是在客户端安装adobe acrobat软件。
使用ShellExecute也可以打开它
 
ning_ning,能否帮我写个简单的例子
 
点击IMPORT ACTIVEX CONTROL菜单,找到ACROBAT CONTROL FOR ACTIVEX
后面我就不用说了吧,它会在ACTIVEX页面生成一个TPDF控件,在你的FORM上加上此控件就行了,调用它的方法载入文件
 
不好意思,看错了题意![:(]
 
后退
顶部