|
楼主 |
发表于 2018-1-31 20:33
|
显示全部楼层
发现公司电脑有FoxitReader 1.0 Type Library,不知道有没有高手能将下面这段代码改成foxit的,因为下面这段代码是Acrobat的,感觉这样的话foxit也有自己的对象属性和方法可以套用,不知道是不是这样。
Function readacrobatdocument(strFileName As String)
'Note: A Reference to the Adobe Library must be set in Tools|References!
Dim AcroApp As Acrobat.CAcroApp, AcroAVDoc As Acrobat.CAcroAVDoc, AcroPDDoc As Acrobat.CAcroPDDoc
Dim AcroHiliteList As Acrobat.CAcroHiliteList, AcroTextSelect As Acrobat.CAcroPDTextSelect
Dim PageNumber, PageContent, Content, i, j
Set AcroApp = CreateObject("AcroExch.App")
Set AcroAVDoc = CreateObject("AcroExch.AVDoc")
If AcroAVDoc.Open(strFileName, vbNull) <> True Then Exit Function
' The following While-Wend loop shouldn't be necessary but timing issues may occur.
While AcroAVDoc Is Nothing
Set AcroAVDoc = AcroApp.GetActiveDoc
Wend
Set AcroPDDoc = AcroAVDoc.GetPDDoc
For i = 0 To AcroPDDoc.GetNumPages - 1
Set PageNumber = AcroPDDoc.AcquirePage(i)
Set PageContent = CreateObject("AcroExch.HiliteList")
If PageContent.Add(0, 9000) <> True Then Exit Function
Set AcroTextSelect = PageNumber.CreatePageHilite(PageContent)
' The next line is needed to avoid errors with protected PDFs that can't be read
On Error Resume Next
For j = 0 To AcroTextSelect.GetNumText - 1
Content = Content & AcroTextSelect.GetText(j)
Next j
Next i
readacrobatdocument = Content
AcroAVDoc.Close True
AcroApp.Exit
Set AcroAVDoc = Nothing
Set AcroApp = Nothing
End Function
Sub demo()
Dim str As String
str = readacrobatdocument("C:\Users\jlin10\Desktop\1.pdf")
Set fs1 = CreateObject("Scripting.FileSystemObject") '创建一个新的文本文件对象
Set a1 = fs1.CreateTextFile("C:\Users\jlin10\Desktop\testfile1.txt", True) '创建这个文件
a1.Writeline (str) '想数据写入TXT文件中
a1.Close '文件关闭
End Sub |
|