Cannot import Icon to Image/Button Field with JavaScript due to security reason.
I want to import a PNG image or, ideally, a single-page PDF file to an Image/Button Field with a script. The Acrobat I installed on my PC is the Pro version, not Acrobat Reader.
My original idea was to run a VBA code in Excel with Acrobat Library. The code shows below:
Sub InsertPDF()
Dim acroApp As Object
Dim arcoDoc As Object
Dim jso As Object
Set acroApp = CreateObject("AcroExch.App")
Set arcoDoc = CreateObject("AcroExch.PDDoc")
Dim insertThisPDFPath As String
Dim targetPDFPath As String
insertThisPDFPath = "C:\Temp\Insert_this.pdf"
targetPDFPath = "C:\Temp\Target.pdf"
arcoDoc.Open (targetPDFPath)
Set jso = arcoDoc.GetJSObject
Dim imageField As Object
Set imageField = jso.getField("Image1_af_image")
imageField.strokeColor = jso.Color.transparent
imageField.fillColor = jso.Color.transparent
imageField.buttonImportIcon insertThisPDFPath
arcoDoc.Save PDSaveFull, "Result.pdf"
arcoDoc.Close
acroApp.Exit
Set arcoDoc = Nothing
Set acroApp = Nothing
End Sub
However, when I ran the code, the PDF file could not be inserted into the Image Field. The colour of the field has been successfully changed to transparent, which means the field setting is correct. Also, the PDF was saved to the correct path. Therefore, I think it must be the issue with "imageField.buttonImportIcon insertThisPDFPath".
After this, I tried to use JavaScript to control the PDF directly. I edited the Action of the field, with ran the following code:
var f = this.getField("Image1_af_image");
f.fillColor = color.transparent;
f.borderColor = color.transparent;
f.buttonImportIcon("/C/Temp/Insert_This.pdf");
Then an Error shown over the Debugger said:
NotAllowedError: Security settings prevent access to this property or method.
I tried to reset every security optional under Preferences, including deselecting the global object security policy and also adding the path to the whitelist. Unfortunately, it still does not work. I guess the original VBA code might also meet this problem so that it cannot work either.
What should I do next? I just want to down-scale and insert a pdf page overlay on another pdf page. Are there any methods with VBA that can achieve this function?
