These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Using doc.importIcon in Reader

jmnw
Registered: Jul 29 2010
Posts: 5

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.

J. Millet

My Product Information:
Reader 9.3, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2398
According to the API reference this method can't be used at all in Reader. Where did you see otherwise?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You have to be careful with this. The 'importIocn' gets an Icon stream stored as a file. So first one has to create the icon stream using the 'buttonImportIcon' method. And the 'buttonImportIcon' is not available to Reader. You may also have to use the trusted function for preforming some of these methods when not used in a batch process or through the console.

George Kaiser

hcv
Registered: Feb 9 2011
Posts: 2
Hi,

I do have the same need: allow a user to load an image into a button field using Adobe Reader using the doc.importIcon method; and found the same NotAllowedError...
Have you succeeded ? How ?

Many thanks
H. Chomel
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
It cannot work with a button created in Acrobat. I really wish Adobe would allow it, because they do with a form created with LiveCycle Designer that uses an image field. Please submit a feature request if you'd like this to appear in a future version: https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
hcv
Registered: Feb 9 2011
Posts: 2
Thank you for your answer even if it's exactly what I feared...
Do you know a workaround without LiveCycle Designer, to allow the end user to load and display an image in a specific place of the PDF form opened in Adobe Reader ? with watermarks or so on... but through the simplest user action...

Best regards,
H. Chomel
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
The only (non-crazy) workaround I'm aware of is to have the user place an image as a stamp. In order for this to work, the user has somehow has to get the image copied to the clipboard (e.g., by opening it in some other program and copying). The user can place the image wherever they want, resize, and even rotate, all of which is normally undesirable. They could also use FoxIt Reader, which allows placing of images as stamps, but without the rigmarole of copying to the clipboard.

The crazy way is to have the user select the file for upload to a web server, submit the file to a web server, and have the server respond with an FDF that populates the button with the icon. It works, but it's obviously a bit involved.