Skip to main content
Participant
November 21, 2019
Question

Acrobat API "ImportAnXFDF" in Acrobat Pro 2017

  • November 21, 2019
  • 2 replies
  • 720 views

When trying to call Acrobat API "ImportAnXFDF" in Acrobat Pro 2017, an exception error "Remote procedure call failed" occurred.

"ImportAnXFDF" is described at "JavaScript for Acrobat API Reference (May 2015)" included in the "Acrobat DC SDK Documentation", so we can use it.

 

Can Acrobat API "ImportAnXFDF" be used in Acrobat Pro 2017?
If so, please tell us how to call it.
If we cannot use it, please tell us the alternative.

Acrobat Pro 2017 version is 17.0.11.30152.

 

In Acrobat XI Pro, no exception error occurred.

This topic has been closed for replies.

2 replies

Thom Parker
Community Expert
Community Expert
November 21, 2019

Acrobat has a habit of reporting the wrong error for many JavaScript calls. Usually it's a security error. I've never seen this one. Please post your code, it could be a problem with the inputs.

Also, is the source of the XFDF file remote?

Can you manually import the same XFDF?

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
November 22, 2019

Thank you for your reply.
Below is the information you asked for.

Version number of Acrobat : Acrobat Pro 2017 (Classic) version 2017.011.30152

OS version : Windows 10 (64bit)
Microsoft Windows Server 2016 Datacenter 10.0.14393 Build 14393 (on VMWare7.1)


Our VB.NET code is following.

Imports Foo.Common
Imports Foo.Common.FooException

Namespace AcroExch

Public Class PDDoc : Inherits PDApp
Implements IDisposable

Private mPDDoc As Acrobat.CAcroPDDoc = Nothing
Private mJso As Object = Nothing

Private mSrcFName As String = ""


Public Sub OpenDoc(ByVal fname As String)

Dim bOK As Boolean
Dim e As FooException = Nothing

Try
    mSrcFName = fname

    ' PDFDoc
    mPDDoc = DirectCast(CreateObject("AcroExch.PDDoc"), Acrobat.CAcroPDDoc)
    If mPDDoc Is Nothing Then
        Throw New FooException(E_ACROEXCH_INIT)
    End If

    bOK = mPDDoc.Open(mSrcFName)
    If bOK <> True Then
        Throw New FooException(E_WOPENFILE)
    End If

    ' JSO
    mJso = mPDDoc.GetJSObject()
    If mJso Is Nothing Then
        Throw New FooException(E_ACROEXCH_INIT)
    End If

Catch ex As FooException
    e = ex
Catch ex As Exception
    e = New FooException(E_NOTREADY, ex.ToString())
Finally
    If Not (e Is Nothing) Then
        Throw e
    End If
End Try
End Sub

Public Sub CloseDoc()
Try
    If Not (mJso Is Nothing) Then
        mJso.closeDoc(True)
    End If
Catch ex As Exception

Finally
    ReleseComObject(mJso)
    mJso = Nothing
End Try

Try
    If Not (mPDDoc Is Nothing) Then
        mPDDoc.Close()
    End If
Catch ex As Exception

Finally
    ReleseComObject(DirectCast(mPDDoc, Object))
    mPDDoc = Nothing
End Try

End Sub

Public Sub ImportAnXFDF(ByVal filename As String)
Try
    Dim jsFName As String = PDApp.GetAcrobatPath(filename)
    mJso.ImportAnXFDF(jsFName)
Catch ex As Exception

End Try
End Sub

Public Sub Save()
    mPDDoc.Save(CShort(Acrobat.PDSaveFlags.PDSaveIncremental), mSrcFName)
End Sub

Public Sub Close()
    mPDDoc.Close()
End Sub

End Class

End Namespace

The exception error occured at "mJso.ImportAnXFDF(jsFName)".

The source of the XFDF file is local.

I can import the same XFDF file manually.

Best regards.

 

Thom Parker
Community Expert
Community Expert
November 22, 2019

So first, it would have been very helpful to know this function was being called from VBA first. That changes everything. This is not an Acrobat error, it's a VB error, probably because the function you're calling has security restrictions.

 

There are many issues with calling JS from a VB app, mostly because of type translation of anyting thats not a scalar. But also because if there is an error with the JS call, you don't get the correct error message.

 

The way to fix this issue, and make your code more reliable in general is to create folder level trusted functions for any JS calls that are either complicated (more then one line of JS), privileged, or pass objects as parameters.  Then call this function from the VB. 

 

 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
November 21, 2019

What's the exact version number of Acrobat? What's your OS version? Can you post your full code?

 

It's possible there's a bug in that version of Acrobat that prevents this method from working, especially if the same thing worked in XI.