Copy link to clipboard
Copied
Hello, everyone,
What code should be added to achieve this function?
Dim gApp, avDoc
Set gApp = CreateObject("AcroExch.app")
Set avDoc = CreateObject("AcroExch.AVDoc")
Dim filepath
filepath = "C:\\test.pdf"
If avDoc.Open(filepath, "") = True Then
avDoc.BringToFront
' add vbscript code in here
avDoc.Close True
Else
Msgbox "Failed to open PDF"
End If
Set pDDoc = Nothing
Set avDoc = Nothing
Set gApp = Nothing
Copy link to clipboard
Copied
Hi @rui huang,
Hope you are doing well. Thanks for writing in!
Here is a sample code you might want to try.
Dim gApp, avDoc
Set gApp = CreateObject("AcroExch.App")
Set avDoc = CreateObject("AcroExch.AVDoc")
Dim filepath
filepath = "C:\\test.pdf"
If avDoc.Open(filepath, "") = True Then
avDoc.BringToFront
' Note: This JavaScript cannot access Preflight
Dim jsCode
jsCode = "console.println('Preflight profiles are not accessible via JavaScript.');"
' Execute JavaScript in Acrobat
Dim jsResult
jsResult = avDoc.ExecuteThisJavaScript(jsCode)
avDoc.Close True
Else
Msgbox "Failed to open PDF"
End If
Set pDDoc = Nothing
Set avDoc = Nothing
Set gApp = Nothing
The code conceptually aligns with how you might combine VBScript and Acrobat's JavaScript API, but there are some issues and limitations to address for it to work correctly with Adobe Acrobat's API.
1. app.execMenuItem('Preflight')
in
Preflight
object and its methods (getProfileByName
and run
) are not accessible through JavaScript alone. They are part of the Acrobat SDK for creating custom plugins, which VBScript cannot invoke directly.2. ExecuteThisJavaScript
:
3. VBScript and Preflight:
Review the Acrobat SDK documentation to understand the capabilities and constraints of VBScript, JavaScript, and plugins.
Hope this helps.
-Souvik
Copy link to clipboard
Copied
Hi @rui huang,
Hope you are doing well. Thanks for writing in!
Here is a sample code you might want to try.
Dim gApp, avDoc
Set gApp = CreateObject("AcroExch.App")
Set avDoc = CreateObject("AcroExch.AVDoc")
Dim filepath
filepath = "C:\\test.pdf"
If avDoc.Open(filepath, "") = True Then
avDoc.BringToFront
' Note: This JavaScript cannot access Preflight
Dim jsCode
jsCode = "console.println('Preflight profiles are not accessible via JavaScript.');"
' Execute JavaScript in Acrobat
Dim jsResult
jsResult = avDoc.ExecuteThisJavaScript(jsCode)
avDoc.Close True
Else
Msgbox "Failed to open PDF"
End If
Set pDDoc = Nothing
Set avDoc = Nothing
Set gApp = Nothing
The code conceptually aligns with how you might combine VBScript and Acrobat's JavaScript API, but there are some issues and limitations to address for it to work correctly with Adobe Acrobat's API.
1. app.execMenuItem('Preflight')
in
Preflight
object and its methods (getProfileByName
and run
) are not accessible through JavaScript alone. They are part of the Acrobat SDK for creating custom plugins, which VBScript cannot invoke directly.2. ExecuteThisJavaScript
:
3. VBScript and Preflight:
Review the Acrobat SDK documentation to understand the capabilities and constraints of VBScript, JavaScript, and plugins.
Hope this helps.
-Souvik
Copy link to clipboard
Copied
Hi Souvik,
Thanks for your reply,
In fact, Preflight can be run via javascript on mac, pls see:
https://community.adobe.com/t5/acrobat-discussions/script-to-pdf-convert-all-text-to-outline/m-p/147...
but I just want to try to implement this function by VBscript on a windows pc
Copy link to clipboard
Copied
Hi Souvik,
when I reset security, add folder path to trust , now I can process preflight via vbscript.
Set pdDoc = avDoc.GetPDDoc
Set jsObj = pdDoc.GetJSObject
Dim jsCode
jsCode = "var oProfile = Preflight.getProfileByName('Convert fonts to outlines'); var myPreflightResult = this.preflight( oProfile);"
AForm.Fields.ExecuteThisJavaScript jsCode