I want to extract selected text from a PDF document. I have checked the material that is available online. Examples available there are first creating the text selection (by passing hard-coded values) on a PDF document and then retrieving it.
Here is the code I am using
Dim nElement As Integer
Dim gAcroRect As Acrobat.CAcroRect
Dim pdTextSelect As Acrobat.CAcroPDTextSelect
Try
gApp = CreateObject("AcroExch.App")
gAvDoc = gApp.GetAVDoc(docNo)
gAvDoc.BringToFront()
gPdDoc = gAvDoc.GetPDDoc()
gAcroRect = CreateObject("AcroExch.Rect")
‘AS YOU CAN SEE FOLLOWING COORDINATES ARE HARD-CODED
gAcroRect.bottom = 380
gAcroRect.Top = 400
gAcroRect.Left = 100
gAcroRect.right = 500
pdTextSelect = gPdDoc.CreateTextSelect(2, gAcroRect)
gAvDoc.SetTextSelection(pdTextSelect)
gAvDoc.ShowTextSelect()
For nElement = 0 To pdTextSelect.GetNumText() - 1
MessageBox.Show("Text # " & nElement & " ---> '" & pdTextSelect.GetText(nElement) & "'")
Next
Catch ex As Exception
End Try
In the code above, object gAcroRect contains the hard-coded parameters to select the specific area. I want to extract just this information when user selects the specific area on a PDF document (I want to pass these parameters dynamically as per the selection user makes on the PDF document).
I tried another way of coping the selected text from the PDF, but I need to retain/ save the word number and page number that belongs to the current selection.
Your suggestions will be highly appreciated.
-Abhijeet
Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]
The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script