Copy link to clipboard
Copied
I am trying to create my first program to interface with Adobe Acrobat Pro DC. I've got to
where I can create an instance of Adobe Acrobat and open a pdf. I now need to create a
text note, set the font style, color, and size. Then place this note in a particular location
on the pdf. I am using this as a stand alone program interfacing with Acrobat through COM.
I'm coding in VB.Net. Does anyone have any sample code for accomplishing this? I've gone
through the samples included with the SDK, but can't find anything on adding a simple note.
Any help would be greatly appreciated. Thanks.
Copy link to clipboard
Copied
‌ACrobat can do so much that you won't generally find samples for anything you want to do. instead it's all about careful study of the documentation. The API you will want to study us the VB:JavaScript linkage which lets you run most JavaScript. That cracked, you can study the HavaScript API. JavaScript can add comments.
Copy link to clipboard
Copied
Ok, I found an example for adding a comment that does a pop up window. But I don't need a pop up window, I need to add a simple line of text. And the code has all the variables declared as "Object". So I don't get intellisense in Visual Studio. Is there a more in depth API reference that lists all the methods for the Java Script Object?
Copy link to clipboard
Copied
Visual Studio will not help you, there is no autocompletion for these methods. You need the Acrobat JavaScript API, which is part of the Acrobat SDK documentation, and runs to many hundreds of pages.
Copy link to clipboard
Copied
Yeah, I found it finally. Been going through it and have gotten it to where I can add some "FreeText" and place it where I want. But I can't get the methods to work for changing the color and font style and size of the font. Could you point me to a specific page in the SDK reference?
Copy link to clipboard
Copied
It's probably better if you post what you are trying to do this, and we can help you understand whether the problem is that you are using the wrong method, or have the wrong syntax. Be sure to check the console for error messages.
Copy link to clipboard
Copied
Try
AcroPpage = CType(AcroPdoc.AcquirePage(0), AcroPDPage)
Catch GetAcrobatPageError As Exception
Debug.WriteLine(GetAcrobatPageError)
End Try
If AcroPpage Is Nothing Then
MessageBox.Show("Error Trying To Get The Java Script Object")
Exit Sub
End If
Try
oJso = AcroPdoc.GetJSObject
Catch GetJsoError As Exception
Debug.WriteLine(GetJsoError)
End Try
If oJso Is Nothing Then
MessageBox.Show("Error Trying To Get The Java Script Object")
Exit Sub
End If
Try
oPageRect = AcroPpage.GetSize
Catch GetAcroRectError As Exception
Debug.WriteLine(GetAcroRectError)
End Try
If oPageRect Is Nothing Then
MessageBox.Show("Error Trying To Get The Acrobat Page Rectangle")
Exit Sub
End If
Try
oAnno = oJso.AddAnnot
Catch CreateAnnoError As Exception
Debug.WriteLine(CreateAnnoError)
End Try
If oAnno Is Nothing Then
MessageBox.Show("Error Trying To Create A New Annotation Object")
Exit Sub
End If
Try
oProps = oAnno.GetProps
Catch GetPropertiesError As Exception
Debug.WriteLine(GetPropertiesError)
End Try
If oProps Is Nothing Then
MessageBox.Show("Error Trying To Get Annotation Properties")
Exit Sub
End If
Try
iPopUpRect(0) = 5
iPopUpRect(1) = oPageRect.y - 50
iPopUpRect(2) = 400
iPopUpRect(3) = oPageRect.y - 5
oProps.Type = "FreeText"
oAnno.SetProps(oProps)
oProps = oAnno.GetProps
oProps.page = 0
oProps.print = True
oProps.alignment = 0
oProps.rect = iPopUpRect
oProps.width = 0
oProps.contents = "I added this comment from Visual Basic!"
'The next three methods are the ones that don't work
oProps.strokeColor = oJso.color.black
oProps.textFont = "Arial-Black"
oProps.textSize = 12
oAnno.SetProps(oProps)
Catch AddTextError As Exception
Debug.WriteLine(AddTextError)
End Try
All of this code runs through without error. It's just the three methods in red above that don't execute correctly. Any help would be greatly appreciated. Thanks.
Copy link to clipboard
Copied
Don't know about colour and size, but the text font looks wrong. The font name to use may not match the name you see in Windows. See the procedure described under JavaScript > JavaScript for Acrobat API Reference > JavaScript API > Field > Field properties > textFont
Find more inspiration, events, and resources on the new Adobe Community
Explore Now