• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

JSObject Doesn't Have Correct Commands

New Here ,
Dec 30, 2017 Dec 30, 2017

Copy link to clipboard

Copied

I have Adobe Acrobat Standard DC installed core version 18.2304. I'm using Visual Studio 2017 and using Visual Basic. I'm trying to create a code to mark a pdf drawing as a draft. I'm starting from the example on one of Adobe's iac developers's guide example thinking that would be a good place to start. I tried out the code that starts on page 23. It didn't work, and I've narrowed the problem to the JSObject. I can use methods from pdDoc to get the correct filename for the PDF, so I think all is working up to that point. The jso object also isn't nothing, so it enders the if statement, but the jso object doesn't have any of the methods used by the pdf example available, so it throws me an error when I try annot = jso.AddAnnot. I have the below references added to the project. Anyone have any idea what the issue might be? Thanks in advance for any help!

http://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/iac_developer_guide.pdf

    Sub StampPDF(ByVal MyPDFPath As String)

        Dim gApp As Acrobat.CAcroApp

        gApp = CreateObject("AcroExch.App")

        Dim pdDoc As Acrobat.CAcroPDDoc

        pdDoc = CreateObject("AcroExch.PDDoc")

        Dim pdAnnot As Acrobat.CAcroPDAnnot

        pdAnnot = CreateObject("AcroExch.PDAnnot")

        Dim PDFResult As Boolean

        Dim page As Acrobat.CAcroPDPage

        Dim jso As Object

        Dim point(1) As Integer

        Dim popupRect(3) As Integer

        Dim pageRect As Object

        Dim annot As Object

        Dim props As Object

        PDFResult = pdDoc.Open(MyPDFPath)

        jso = pdDoc.GetJSObject

        If Not jso Is Nothing Then

            ' Get size for page 0 and set up arrays

            page = pdDoc.AcquirePage(0)

            pageRect = page.GetSize

            point(0) = 0

            point(1) = pageRect.y

            MsgBox(point(1))

            popupRect(0) = 0

            popupRect(1) = pageRect.y - 100

            popupRect(2) = 200

            popupRect(3) = pageRect.y

            ' Create a new text annot

            '        annot = jso.AddAnnot

            '        props = annot.getProps

            '        props.Type = "Text"

            '        'annot.setProps props

            '        ' Fill in a few fields

            '        props = annot.getProps

            '        props.page = 0

            '        props.point = point

            '        props.popupRect = popupRect

            '        props.author = "John Doe"

            '        props.noteIcon = "Comment"

            '        props.strokeColor = jso.Color.red

            '        props.Contents = "I added this comment from Visual Basic!"

            '    'annot.setProps props

        End If

    End Sub

TOPICS
Acrobat SDK and JavaScript

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 30, 2017 Dec 30, 2017

Copy link to clipboard

Copied

That's not a very good example.  There are serious problems with translating between VB objects and JS objects. You are much better off writing the functionality you want as a folder level JavaScript function, then calling this function from the JSO in VB.  Also restrict everything you pass into the JSO function calls to string and scalar values

However, I believe the specific issue with your script is that JS is case sensitive, and there are capitals in the wrong places. You also don't need to set many of the other annot properties, such as all the popup stuff. And "point" is not a property of the text annot.

Try using:

annot = jso.addAnnot

The "a" in addAnnot is lower case. The same is true for "type" and "color".

But again, I would not do any of this in the VB code. Instead I would write the functionality as a Folder Level JavaScript function and then call the function from the VB.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 30, 2017 Dec 30, 2017

Copy link to clipboard

Copied

In addition, you'll note the explanation text on Page 25 of the IAC developer guide shows the correct capitalization of "addAnnot". So this is most likely an error in the guide.

It also explains that there is a performance issue with making multiple calls to the JSO.  Another good reason to use a folder level JS function instead of all these calls.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 20, 2021 Dec 20, 2021

Copy link to clipboard

Copied

LATEST

I changed the code in the guide slightly, it works on visual studio 2017:

 

Dim gApp As Acrobat.CAcroApp
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
gApp = CreateObject("AcroExch.App")
End Sub
Private Sub Form1_Closed(Cancel As Integer)
If Not gApp Is Nothing Then
gApp.Exit
End If
gApp = Nothing
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim pdDoc As Acrobat.CAcroPDDoc
Dim page As Acrobat.CAcroPDPage
Dim jso As Object
Dim path As String
Dim point(1) As Integer
Dim popupRect(3) As Integer
Dim pageRect As Object
Dim annot As Object
Dim props As Object
OpenFileDialog1.ShowDialog()
path = OpenFileDialog1.FileName
pdDoc = CreateObject("AcroExch.PDDoc")

If pdDoc.Open(path) Then
jso = pdDoc.GetJSObject
If Not jso Is Nothing Then
' Get size for page 0 and set up arrays
page = pdDoc.AcquirePage(0)
pageRect = page.GetSize
point(0) = 0
point(1) = pageRect.y
popupRect(0) = 0
popupRect(1) = pageRect.y - 100
popupRect(2) = 200
popupRect(3) = pageRect.y
' Create a new text annot
annot = jso.AddAnnot
props = annot.getProps
props.Type = "Text"
annot.setProps(props)

' Fill in a few fields
props = annot.getProps
props.page = 0
props.point = point
props.popupRect = popupRect
props.author = "Guilan Huang"
props.noteIcon = "Comment"
props.strokeColor = jso.Color.red
props.Contents = "I added this comment from Visual Basic!"
annot.setProps(props)
End If
pdDoc.Close()
MsgBox("Annotation added to " & path)
Else
MsgBox("Failed to open " & path)
End If
pdDoc = Nothing
End Sub

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines