Skip to main content
Participant
July 12, 2022
Question

SDK, JavaScript Object SaveAs no longer working.

  • July 12, 2022
  • 1 reply
  • 1712 views

Hello.

I have been running the following VBA code without issue for a while. After the latest update to Acrobat Pro DC I have been getting the following error: Save As Failed To Process. No document was created.

 

The code is failing on the JSO.SaveAs line.

Function SaveAs(NewFileName As String) As Boolean
    Dim ExportFormat As String
    Dim extension As String
    extension = "html" ' get the path w/o the "."
    
    Dim acroApp As Object
    Set acroApp = CreateObject("AcroExch.App")
    Dim acroAVDoc As Object
    Set acroAVDoc = CreateObject("AcroExch.AVDoc")
    'if acroApp is nothing then acroApp = CreateObject("AcroExch.App")
    'if acroAVDoc is nothing then acroAVDoc = CreateObject("AcroExch.AVDoc")
    
    Set acroAVDoc = acroApp.GetActiveDoc()
    
    If acroAVDoc Is Nothing Then
        Exit Function
    End If
    
    'Set the PDDoc object.
    Dim acroPDDoc As Object
    Set acroPDDoc = acroAVDoc.GetPDDoc
    
    'Set the JS Object - Java Script Object.
    Dim jso As Object
    Set jso = acroPDDoc.GetJSObject
    
    'Check the type of conversion.
    Select Case LCase(extension)
        Case "eps": ExportFormat = "com.adobe.acrobat.eps"
        Case "html", "htm": ExportFormat = "com.adobe.acrobat.html"
        Case "jpeg", "jpg", "jpe": ExportFormat = "com.adobe.acrobat.jpeg"
        Case "jpf", "jpx", "jp2", "j2k", "j2c", "jpc": ExportFormat = "com.adobe.acrobat.jp2k"
        Case "docx": ExportFormat = "com.adobe.acrobat.docx"
        Case "doc": ExportFormat = "com.adobe.acrobat.doc"
        Case "png": ExportFormat = "com.adobe.acrobat.png"
        Case "ps": ExportFormat = "com.adobe.acrobat.ps"
        Case "rft": ExportFormat = "com.adobe.acrobat.rft"
        Case "xlsx": ExportFormat = "com.adobe.acrobat.xlsx"
        Case "xls":
            ExportFormat = "com.adobe.acrobat.spreadsheet"
            'Note that Adobe instead of xls uses xml files.
    '        newFilename.Replace(extension,"xml")
        Case "txt": ExportFormat = "com.adobe.acrobat.accesstext"
        Case "tiff", "tif": ExportFormat = "com.adobe.acrobat.tiff"
        Case "xml": ExportFormat = "com.adobe.acrobat.xml-1-00"
        Case Else: ExportFormat = "Wrong Input"
    End Select
    
    
    'Check if the format is correct and there are no errors.
    If ExportFormat <> "Wrong Input" Then
        'Save PDF file to the new format.
            Call jso.SaveAs(NewFileName, ExportFormat)
            SaveAs = True
    Else
        SaveAs = False
    End If
    'Release the objects.
    Set jso = Nothing
    Set acroPDDoc = Nothing
    Set acroAVDoc = Nothing
    Set acroApp = Nothing
End Function

 Does anyone have any ideas as to why this just started to fail?

This topic has been closed for replies.

1 reply

LesZAuthor
Participant
July 12, 2022

Sometimes you need to cry for help so that you can figure it out yourself. During our latest SCCM update to the latest version the enhanced security was re-enabled. I resolved the issue by turning that off.