Copy link to clipboard
Copied
The end goal: Programmatically add annotations to a PDF through a VB.Net Windows Form Document.
The Issue: Using the AddAnnot() jsObj situation.
Where I'm stuck:
I've found some great Adobe references that seemed very promising and have answered some other questions. My issue is that in the "Javascript for Acrobat API Reference" the Parameters for the AddAnnot() function (I think that function is the right word) are not as explicit as others. For example, the addWaterMarkFromFile() reference lists 16 parameters, each with a name, what they're specifying, and their default values. In the SDK reference for the addWaterMarkFromFile() there are 16 parameters specified, and they can be manipulated in a sensible enough manner. The example:
However, with the AddAnnot() reference the only parameter listed is an "object literal", which is described as containing the properties of the Annotation object.
I've found the list of the properties, and with what syntax can I specify some of all of them? The reference shows them specifed as follows:
var sqannot = this.addAnnot({type: "Square", page: 0});
or
var annot = this.addAnnot
({
page: 0,
type: "Text",
author: "A. C. Robat",
point: [300,400],
strokeColor: color.yellow,
contents: "Need a little help with this paragraph.",
noteIcon: "Help"
});
My rationale (which is incorrect) suggests that I could call the second example by:
Dim srcPage As Acrobat.CAcroPDPage
srcPage = CreateObject("AcroExch.PDPage")
jsStampObj = srcDoc.GetJSObject
jsStampObj.AddAnnot(0, "Text", "A. C. Robat", New Point(300,400), jsStampObj.Color.Blue, "Need a little help with this paragraph", "Help")
But I'm unsure if the above is even remotely correct either, as I haven't specified any page to which the annotation should be added. My efforts thus far have been to shove that code into the loop the WaterMarkJsoVB() project from the SDK uses to place watermarks. The addWaterMarkfromFile has a parameter for the document to which it should be pointing and the page on which ti place the mark, I've seen no such parameter in any reference relating to Add Annot. Still unsure how to point at pages too well, and have only had success with PDDoc objects and splitting pages / creating new pdfs, straight from the SDK.
I digress! Any input?
You have to do this in multiple steps. Here is a sample from an application that creates a stamp annotation. You will have to adjust the annotation type for your specific situation:
...Dim stampRect(3) As Integer
Dim annot As Object
Dim props As Object
Set jso = gPDDoc.GetJSObject
stampRect(0) = 100
stampRect(1) = 100
stampRect(2) = 200
stampRect(3) = 200
' Create a new stamp annot
Set annot = jso.AddAnnot
Copy link to clipboard
Copied
You have to do this in multiple steps. Here is a sample from an application that creates a stamp annotation. You will have to adjust the annotation type for your specific situation:
Dim stampRect(3) As Integer
Dim annot As Object
Dim props As Object
Set jso = gPDDoc.GetJSObject
stampRect(0) = 100
stampRect(1) = 100
stampRect(2) = 200
stampRect(3) = 200
' Create a new stamp annot
Set annot = jso.AddAnnot
' Get the cannot properties, change the type and then push it to the cannot object again
Set props = annot.getprops
props.Type = "Stamp"
annot.setProps props
' Fill in the necessary fields
Set props = annot.getprops
props.Page = 0
props.rect = stampRect
props.Author = "My Name"
props.AP = "Approved"
annot.setProps props
Copy link to clipboard
Copied
Thank you; this went well with a little tweaking. Below is my final code for the reference of others who may stumble by. It includes some superfluous declarations and commented-out sections that didn't work.
Thanks again, Karl. I've stumbled across an article or two of yours and they are much appreciated!
Public Class Form1
Dim gApp As Acrobat.CAcroApp
Dim gPDDoc As Acrobat.CAcroPDDoc
Dim gAVDoc As Acrobat.CAcroAVDoc
Dim gAVPage As Acrobat.CAcroAVPageView
Dim gPDPageStart As Object
Dim gPDPage As Acrobat.CAcroPDPage
Dim jso As Object
Dim jstamp As Object
Dim stampRect(3) As Integer
Dim annot As Object
Dim props As Object
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
gApp = CreateObject("AcroExch.App")
gAVDoc = CreateObject("AcroExch.AVDoc")
gPDDoc = CreateObject("AcroExch.PDDoc")
If gPDDoc.Open( <Filename> ) Then
jso = gPDDoc.GetJSObject
stampRect(0) = 100
stampRect(1) = 100
stampRect(2) = 200
stampRect(3) = 200
annot = jso.AddAnnot()
props = annot.getprops()
props.Type = "Stamp"
annot.setProps(props)
props = annot.getprops
props.Page = 0
props.opacity = 1
props.rect = stampRect
props.Author = "Matt"
props.AP = "Draft"
annot.setProps(props)
'gAVPage = gAVDoc.GetAVPageView
'gPDPageStart = gAVPage.GetPage()
'gPDPage = gPDPageStart
'gPDPage.AddAnnot(1,)
'jstamp = gPDPage.AddNewAnnot(0, "Stamp", New Rectangle(New Point(500, 500), New Size(2000, 2000)))
MessageBox.Show("Working")
'MessageBox.Show(jso.CountAllBookmarks())
End If
End Sub
End Class
Find more inspiration, events, and resources on the new Adobe Community
Explore Now