I am attempting to allow a user to load an image into a button field using Adobe Reader using the doc.importIcon method.
This is being done using javascript for a form built in Adobe Acrobat 8.0, testing with Adobe Reader 9.3.4.
I thought this was possible because the method is marked in the JS API with a red S. According to the documentation, this means that this method should work if any of the following are true:
1) The document is certified and the certificate is trusted by the user and allows high level js execution.
2) The function is called from a menu item and the preference setting Enable Menu Items Javascript Execution is checked.
3) If the menu item function is a trusted function.
I have tried all of these methods and continue to get the error
NotAllowedError: Security settings prevent access to this property or method.
Doc.importIcon
First I placed the following script in a button and then certified the PDF and enabled it to be saved in Reader:
var b = this.getField("pg3.pic1") ;
this.importIcon("image1") ;
b.buttonSetIcon(this.getIcon("image1"));
This worked successfully in Acrobat, but not in Reader even with the trusted certificate.
So then I tried executing it from a menu item, running the item for each page with button fields on it:
function importImage()
{
app.beginPriv() ;
var pn = this.pageNum ;
for (var ifc = 0 ; ifc < this.numFields ; ifc++)
{
if (this.getField(this.getNthFieldName(ifc)).type != "button" && this.getField(this.getNthFieldName(ifc)).page == pn)
{
var b = this.getField(this.getNthFieldName(ifc)) ;
this.importIcon("image") ;
b.buttonSetIcon(this.getIcon("image"));
}
}
app.endPriv() ;
}
app.trustedFunction(importImage) ;
//app.addSubMenu({ cName: "iCiX Standard", cParent: "Tools", nPos: 0 })
app.addMenuItem( {
cUser: "Add Images" ,
cName: "add_image" ,
cParent: "Tools" ,
cExec: "importImage()"
} )
This didn't work using Reader either.
Has anyone successfully used this function in Reader? I checked the latest API documentation and it still claims this should be do-able? Is there an error in my execution? Or am I misunderstanding the documentation?
Any help would be appreciated,
Thanks.
- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com