这个是我以前收藏的代码,提取 PDF 中的关键字,储存到游标中,
直接代开 PDF 文件,不需要另存为 TXT 文件。
需要下载 Adobe SDK 包
Clear
loAcroApp = Createobject("AcroExch.App")
loAcroApp.Minimize(.T.)
loAcroApp.Show()
loAVDoc = Createobject("AcroExch.AVDoc")
lcPdfFile = "D:\MyPath\MyVFP.pdf"
loAVDoc.Open(lcPdfFile, "PDF")
loAvPage = loAVDoc.GetAVPageView()
loPDDoc = loAVDoc.GetPDDoc()
* # of pages in the PDF
lnNumPages = loPDDoc.GetNumPages()
loAVDoc.ClearSelection()
Create Cursor crsTextFound ( PageNum I, Offset I)
llCaseSensitive
= .T.
llWholeWordsOnly = .T.
* Start search from the beginning (Page 0)
llReset = .T.
lcSearchFor = "这里是你要搜索的字符串/Key"
llTextFound = loAVDoc.FindText(lcSearchFor, llCaseSensitive, llWholeWordsOnly, llReset)
* Start search on the current page
llReset = .F.
lnCount = 0
lnPageNum = 0
Do While llTextFound
lnOffset = 0
lnPageNum = loAvPage.GetPageNum()
Insert Into crsTextFound
Values (lnPageNum, lnOffset)
lnCount = lnCount + 1
If lnPageNum+1 >= lnNumPages
Exit
Endif
loAVPage.Goto(lnPageNum+1)
llTextFound = loAVDoc.FindText(lcSearchFor, llCaseSensitive, llWholeWordsOnly, llReset)
Wait Window Nowait "Page " + Transform(lnPageNum+1) + " of " + Transform(lnNumPages)
Enddo
loAcroApp.Restore(.T.)
If Reccount() > 0
* Move to the first page where text has been found
Go Top
loAVPage.Goto(crsTextFound.PageNum)
llTextFound = loAVDoc.FindText(lcSearchFor, llCaseSensitive, llWholeWordsOnly, llReset)
Endif
loAvPage = Null
* Close Acrobat, if necessary
* loPDDoc.Close()
* loPDDoc = Null
* loAVDoc.Close(.T.)
* loAVDoc = Null
* Exit acrobat
* loAcroApp.Exit()
Wait Clear
Return