Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adobe Acrobat Automation
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
01019178
Message ID:
01019408
Views:
135
This message has been marked as the solution to the initial question of the thread.
>Hi, I need to find some keywords inside a PDF document, store all ocurrences in a Table with the page and position of the keyword (inside the document)and present this page to the users with the keyword highlighted. Anyone can help me?

Below's a sample code that shows how to find all pages with specified text. For details see Acrobat Interapplication Communication Reference which you can download from http://partners.adobe.com/public/developer/acrobat/sdk/index_doc.html
CLEAR
loAcroApp = CREATEOBJECT("AcroExch.App")
loAcroApp.Minimize(.T.)
loAcroApp.Show()
loAVDoc = CREATEOBJECT("AcroExch.AVDoc")
lcPdfFile = "Q:\DEV\HELP\OfficeAutomationVFP.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 = "Advanced"

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
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform