ADOBE的帮助是英文的,太长没办法看下去,有<br>那位高手能给我示例一个<br>原来有一个VB的程序也是读取PDF数据的其中的代码如下<br>我没弄懂,用DELPHI该怎么写?Const HKEY_CURRENT_USER = &H80000001<br>Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long<br>' Note that if you declare the lpData parameter as String, you must pass it By Value.<br>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<br>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<br>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<br>Const ChunkSize As Integer = 16384<br>'用api函数读取<br>Private Sub GetMailList_Click()<br>On Error GoTo quit<br> <br> Dim lResult, lRootKey, lKey As Long<br> Dim lSubKeys As Long<br> Dim lValues As Long<br> Dim KeyName As String<br> Dim lKeyNameSize, lTempKeyNameSize As Long<br> Dim KeyValue As String<br> Dim lKeyValueSize, lTempKeyValueSize As Long<br> Dim i As Integer<br> Dim OEStorePath As String<br> Dim UserProfile As String<br> Dim fso As New FileSystemObject<br> <br> lResult = RegOpenKey(HKEY_CURRENT_USER, "Identities", lRootKey)<br> <br> If lResult = 0 Then<br> lResult = RegQueryInfoKey(lRootKey, 0&, 0&, 0&, 0&, 0&, 0&, lValues, lKeyNameSize, lKeyValueSize, 0&, 0&
<br> <br> If lResult = 0 Then<br> For i = 0 To lValues - 1<br> lTempKeyNameSize = lKeyNameSize + 1<br> KeyName = String(lKeyNameSize + 1, " ")<br> lTempKeyValueSize = lKeyValueSize + 1<br> KeyValue = String(lKeyValueSize + 1, " ")<br> <br> lResult = RegEnumValue(lRootKey, i, KeyName, lTempKeyNameSize, 0&, 0&, KeyValue, lTempKeyValueSize)<br> <br> ' trim the null at the end of the returned value<br> If InStr(KeyName, "Default User ID") > 0 Then<br> Exit For<br> End If<br> Next i<br> End If<br> <br> lResult = RegOpenKey(lRootKey, Left$(KeyValue, lTempKeyValueSize - 1) + "/Software/Microsoft/Outlook Express/5.0", lKey)<br> lResult = RegQueryInfoKey(lKey, 0&, 0&, 0&, 0&, 0&, 0&, lValues, lKeyNameSize, lKeyValueSize, 0&, 0&
<br> <br> If lResult = 0 Then<br> For i = 0 To lValues - 1<br> lTempKeyNameSize = lKeyNameSize + 1<br> KeyName = String(lKeyNameSize + 1, " ")<br> lTempKeyValueSize = lKeyValueSize + 1<br> KeyValue = String(lKeyValueSize + 1, " ")<br> <br> lResult = RegEnumValue(lKey, i, KeyName, lTempKeyNameSize, 0&, 0&, KeyValue, lTempKeyValueSize)<br> <br> ' trim the null at the end of the returned value<br> If Left$(KeyName, lTempKeyNameSize) = "Store Root" Then<br> OEStorePath = Left$(KeyValue, lTempKeyValueSize - 1)<br> Exit For<br> End If<br> Next i<br> End If<br> End If<br> <br> <br> If Left$(OEStorePath, 1) = "%" Then<br> UserProfile = Environ("UserProfile")<br> OEStorePath = UserProfile + Mid$(OEStorePath, 14)<br> End If<br> <br> If Right$(OEStorePath, 1) = "/" Then<br> fso.CopyFile OEStorePath + "收件箱.dbx", App.Path + "/收件箱.dbx"<br> Else<br> fso.CopyFile OEStorePath + "/收件箱.dbx", App.Path + "/收件箱.dbx"<br> End If<br> <br> If fso.FileExists(App.Path + "/maillist.ini") Then<br> fso.DeleteFile App.Path + "/maillist.ini"<br> End If<br> <br> 'get pdf list<br> Shell App.Path + "/GetPDF.exe 收件箱.dbx", vbHide<br><br> Progress.Show vbModal<br> <br>quit:<br>End Sub<br><br>Private Sub Submit_Click()<br> Dim i, j, k As Integer<br> Dim sTemp As String<br> Dim avDoc As Variant<br> Dim formApp As Variant<br> Dim acroForm As Variant<br> Dim fld As Variant<br> Dim FileNumber As Integer<br> Dim InBuf As String<br> Dim info() As String<br> Dim formName() As String<br> Dim FormNumber As Integer<br> Dim DBName() As String<br> Dim TempFormName As String<br> Dim TempDBName() As String<br> Dim sSQL As String<br> Dim ws As rdoEnvironment<br> Dim db As rdoConnection<br> Dim rs As rdoResultset<br> Dim TableDefs As rdoTable<br> Dim FieldDefs As Variant<br> Dim DataFile As Integer, Fl As Long, Chunks As Integer<br> Dim Fragment As Integer, Chunk() As Byte<br> <br> 'Set the mouse icon to display an hourglass<br> <br> <br> Dim Item As MSComctlLib.ListItem<br> <br> <br> <br> i = 0<br> For Each Item In MailList.ListItems<br> If Item.Checked Then<br> i = i + 1<br> End If<br> Next<br> If i > 0 Then 'if have mailitem checked<br> Screen.MousePointer = 11<br> StoreDBProgress.Show<br> StoreDBProgress.DBProgressBar.Max = i<br> <br> i = 0<br> For Each Item In MailList.ListItems<br> <br> If Item.Checked Then<br> <br> i = i + 1<br> StoreDBProgress.DBProgressBar.Value = i<br> <br> FileNumber = FreeFile<br> <br> 'Get all keywords from type file<br> j = 0<br> Open App.Path + "/" + PDFList(Item.Index - 1) + ".type" For Input As FileNumber<br> Do While Not EOF(FileNumber)<br> Line Input #FileNumber, InBuf<br> <br> InBuf = Trim(InBuf)<br> If InBuf <> "" Then<br> info = Split(InBuf, " -> ")<br> <br> If info(0) = "√" Then<br> ReDim Preserve formName(j + 1)<br> ReDim Preserve DBName(j + 1)<br> formName(j) = info(1)<br> DBName(j) = info(2)<br> j = j + 1<br> End If<br> End If<br> Loop<br> <br> Close #FileNumber<br> <br> If j = 0 Then<br> MsgBox "注意,该PDF文件没有定义关键字,请重新定义!", vbExclamation, "注意"<br> Exit Sub<br> End If<br> <br> 'Open the PDF file<br> <br> Set avDoc = CreateObject("AcroExch.AVDoc")<br> bOK = avDoc.Open(App.Path + "/Workspace/" + Item.SubItems(4), "")<br> <br> 'If everything was OK opening the PDF, we now instantiate the Forms<br> 'Automation object.<br> If bOK Then<br> Set formApp = CreateObject("AFormAut.App")<br> Set acroForm = formApp.Fields<br> Else<br> Set avDoc = Nothing<br> MsgBox "打开PDF文件失败!", vbExclamation, "注意"<br> GoTo quit<br> End If<br><br> 'Check if this pdf exists enough keywords<br> 'FormNumber = 0<br> 'For Each fld In acroForm<br> ' For k = 0 To j - 1<br> ' If fld.Name = formName(k) Then<br> ' FormNumber = FormNumber + 1<br> ' End If<br> ' Next k<br> 'Next<br> <br> 'It means this pdf file have enough keywords<br> 'If FormNumber >= j Then<br> info = Split(DBName(j - 1), ".")<br> Set ws = rdoEngine.rdoEnvironments(0)<br> Set db = ws.OpenConnection(info(0))<br> <br> <br> Set rs = db.OpenResultset("select count(*) from " + info(1) + " where pdfname='" + Item.SubItems(4) + "'")<br> <br> 'MsgBox rs.rdoColumns(0).Value<br> <br> If rs.rdoColumns(0).Value = 0 Then<br> 'insert<br> info = Split(DBName(j - 1), ".")<br> <br> <br> 'MsgBox "insert into " + Info(1) + "(pdfname) values('" + Item.SubItems(4) + "')"<br> 'insert<br> db.Execute ("insert into " + info(1) + "(pdfname) values('" + Item.SubItems(4) + "')")<br> <br> End If<br> <br> 'update<br> <br> Open App.Path + "/" + PDFList(Item.Index - 1) + ".type" For Input As FileNumber<br> Do While Not EOF(FileNumber)<br> Line Input #FileNumber, InBuf<br> <br> InBuf = Trim(InBuf)<br> If InBuf <> "" Then<br> info = Split(InBuf, " -> ")<br> <br> If info(0) <> "√" And info(0) <> "[PDF文件名]" And info(0) <> "[PDF文件本身]" Then<br> <br> TempFormName = info(0)<br> TempDBName = Split(info(1), ".")<br> <br> sSQL = "update " + TempDBName(1) + " set " + TempDBName(2) + "="<br> <br> Dim bExists As Boolean<br> bExists = False<br> For Each fld In acroForm<br> If fld.Name = TempFormName Then<br> bExists = True<br> <br> 'check its type<br> For Each TableDefs In db.rdoTables<br> If TempDBName(1) = TableDefs.Name Then<br> For Each FieldDefs In TableDefs.rdoColumns<br> If FieldDefs.Name = TempDBName(2) Then<br> 'char<br> If FieldDefs.Type = rdTypeCHAR Or FieldDefs.Type = rdTypeVARCHAR Then<br> sSQL = sSQL + "'" + fld.Value + "' where pdfname='" + Item.SubItems(4) + "'"<br> Else 'number<br> If Len(fld.Value) <> 0 Then<br> sSQL = sSQL + fld.Value + " where pdfname='" + Item.SubItems(4) + "'"<br> Else<br> sSQL = sSQL + "0 where pdfname='" + Item.SubItems(4) + "'"<br> End If<br> End If<br> <br> 'exit loop<br> Exit For<br> End If<br> Next FieldDefs<br> <br> 'exit loop<br> Exit For<br> End If<br> Next TableDefs<br> <br> 'exit loop<br> Exit For<br> End If<br> Next<br> <br> If Not bExists Then<br> sSQL = sSQL + "'无'"<br> End If<br> <br> 'MsgBox sSQL<br> 'update<br> db.Execute (sSQL)<br><br> End If<br> End If<br> Loop<br> <br> Close #FileNumber<br> <br> 'close the resultset<br> rs.Close<br> <br> 'process pdf filename and pdf<br> Open App.Path + "/" + PDFList(Item.Index - 1) + ".type" For Input As FileNumber<br> Do While Not EOF(FileNumber)<br> Line Input #FileNumber, InBuf<br> <br> InBuf = Trim(InBuf)<br> If InBuf <> "" Then<br> info = Split(InBuf, " -> ")<br> <br> If info(0) = "[PDF文件本身]" Then<br> TempDBName = Split(info(1), ".")<br> <br> 'the result of query<br> Set rs = db.OpenResultset("select * from " + TempDBName(1) + " where pdfname='" + Item.SubItems(4) + "'", rdOpenKeyset, rdConcurRowVer)<br> <br> If rs.RowCount <> 0 Then<br> rs.Edit<br> DataFile = 100<br> Open App.Path + "/Workspace/" + Item.SubItems(4) For Binary Access Read As DataFile<br> Fl = LOF(DataFile) ' Length of data in file<br> If Fl = 0 Then Close DataFile: Exit Do<br> Chunks = Fl / ChunkSize<br> Fragment = Fl Mod ChunkSize<br> rs.rdoColumns(TempDBName(2)).AppendChunk Null<br> ReDim Chunk(Fragment)<br> Get DataFile, , Chunk()<br> rs.rdoColumns(TempDBName(2)).AppendChunk Chunk()<br> ReDim Chunk(ChunkSize)<br> For k = 1 To Chunks<br> Get DataFile, , Chunk()<br> rs.rdoColumns(TempDBName(2)).AppendChunk Chunk()<br> Next k<br> Close DataFile<br> rs.Update<br> End If<br> <br> 'exit loop<br> Exit Do<br> End If<br> End If<br> Loop<br><br> db.Close<br> ws.Close<br> <br> 'End If<br> <br> Set avDoc = Nothing<br> <br> End If<br> Next<br> <br> Screen.MousePointer = 4<br> Unload StoreDBProgress<br> MsgBox "注意,PDF文件入库结束!", vbInformation, "注意"<br>End If<br> GoTo Ok<br> <br>quit:<br><br> MsgBox "注意,入库过程出现错误,请修改文档的内容!", vbExclamation, "注意"<br> Screen.MousePointer = 4<br> Unload StoreDBProgress<br><br>Ok:<br><br>End Sub<br><br><br>