I am doing a PDF compare application using VB.NET and JSObject. I did all the compare logic and extracted all the mismatching words and their X-Y co-ordinates. Now its the time to highlight all the acquired co-ord with some color. I get 8 values when I get access the co-ord using the below fn.
oCoord = JSO.getPageNthWordQuads(Page, Word)
I tried up the following with simple X-Y co-ordinates it works great. But when I give using the co-ordinates what I get from the exact location (i.e., I get 8 values which describe a rectangle), I get the following error,
"Value does not fall within the expected range."
Here is the failed code -
page = pdDoc.AcquirePage(0)
'' I get pageRect.Y = 842 and pageRect.X = 595
pageRect = page.GetSize
popupRect(0) = 36D
popupRect(1) = 673.171997070312D
popupRect(2) = 96.69580078125D
popupRect(3) = 673.171997070312D
popupRect(4) = 36D
popupRect(5) = 659.300109863281D
popupRect(6) = 96.69580078125D
popupRect(7) = 659.300109863281D
annot = jso.AddAnnot
props = annot.getProps
props.Type = "Highlight"
annot.setProps(props)
props = annot.getProps
props.page = 0
props.popupRect = popupRect
props.strokeColor = jso.Color.Yellow
annot.setProps(props)
What is that I am missing? Or do I need to do some manipulation with the co-ordinates.
Here is the code which works fine -
page = pdDoc.AcquirePage(0)
'' I get pageRect.Y = 842 and pageRect.X = 595
pageRect = page.GetSize
popupRect(0) = 0
popupRect(1) = pageRect.y
popupRect(2) = 200
popupRect(3) = pageRect.y
annot = jso.AddAnnot
props = annot.getProps
props.Type = "Highlight"
annot.setProps(props)
props = annot.getProps
props.page = 0
props.popupRect = popupRect
props.strokeColor = jso.Color.Yellow
annot.setProps(props)
Is the second set of code really working as far as placing the highlight? or is it just not throwing an error?
There is an example of createing a "Text Markup" annotation in the Acrobat JavaScript Reference, Look up the "getPageNthWordQuads" function. Also read about the annot.quads property. It's a list of points that from a rectangle around the text. A simple rectangle cannot be used because the text might be rotated.
Here is an artical that explains about page coords and adding annotations to a PDF.
http://www.acrobatusers.com/tutorials/2007/10/auto_placement_annotations/
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script