Use VBA to create a highlight annotation in a .pdf document

mike72384

New Member
Joined
Aug 18, 2014
Messages
12
I am trying to figure out how to use VBA to programmatically create a highlight annotation in a .pdf document. I am using the Adobe Acrobat 10.0 Type Library reference and I have set the objects for the document and page that I want. Below is an example of a code that IS working, but I cannot seem to figure out the language for a "highlight" annotation that would need a bounding rectangle rather than a "Text" annotation which only needs 2 points like below. The result in the .pdf document from the code below is that a sticky note is created in the .pdf based on the coordinates "Lpos" and "Tpos".Sub CreateAnnotation(PDDoc As Acrobat.CAcroPDDoc, page As Acrobat.CAcroPDPage, Lpos, Tpos, CommentString)
'Creates an annotation "Sticky Note" in a .pdf document
Dim HiList As Acrobat.AcroHiliteList
Dim PDTextSelect As Acrobat.CAcroPDTextSelect
Dim PDRec As AcroRect

Dim jso As Object
Dim path As String
Dim point(1) As Integer
Dim t As Integer
Dim popupRect(3) As Integer
Dim pageRect As Object
Dim annot As Object
Dim props As Object

Set jso = PDDoc.GetJSObject
Set pageRect = page.GetSize
point(0) = Lpos
point(1) = Tpos
popupRect(0) = 0
popupRect(1) = pageRect.y - 100
popupRect(2) = 100
popupRect(3) = pageRect.y - 200
' Create a new text annot
Set annot = jso.AddAnnot
Set props = annot.getProps
props.Type = "Text"
annot.setProps props
' Fill in a few fields
Set props = annot.getProps
props.page = page.GetNumber
props.point = point
props.popupRect = popupRect
props.Author = "mthompson"
props.noteIcon = "Comment"
props.strokeColor = jso.Color.blue
props.Contents = CommentString
annot.setProps props
End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top