Wednesday, June 17, 2009

How to highlight first word of first page of any PDF file using QTP.

See main post here.

gPDFPath = "C:\Tips.pdf"

'AcroExch.App object allows you to control Acrobat

set gApp = CreateObject("AcroExch.App")
gApp.Show()

'AcroExch.AVDoc: creates an object to manipulate the actual PDF document

set gAvDoc = CreateObject("AcroExch.AVDoc")
gAvDoc.Open gPDFPath,""

'GetAVPageView returns AcroExch.AVPageView and AcroExch.AVPageView is an area of the Acrobat application’s window that displays the contents of a document’s page.

set acroPageView = gAvDoc.GetAVPageView()
acroPageView.GoTo(0)' goes to the first page which is there on opening the document

'the Hilite list object is being created

set ourhitlist = CreateObject("AcroExch.HiliteList")
ourhitlist.Add 0, 1 'starting from 0 offset and first word
set d_page = acroPageView.GetPage()
set Select_text = d_page.CreateWordHilite(ourhitlist)
gAvDoc.Settextselection(Select_text)
wait 5
gAvDoc.Showtextselect()
gAvDoc.Close(True)