Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

buttonGetIcon return value

New Here ,
Sep 11, 2020 Sep 11, 2020

I have sifted thru posts, but can't find a solution ...

I want to execute a script from a button that will evaluate many image fields to determine if an image is assigned to the field.  The purpose is to clear a hidden text field of the original path of the imported icon in each. I have tried:

var isIcon = this.getField("Image17_af_image").value;

which returns "null"

var isIcon = this.getField("Image17_af_image").buttonGetIcon();

which returns [object Icon]

var isIcon = util.iconStreamFromIcon(this.getField("Image17_af_image").buttonGetIcon());

which returns [object Stream]

Is it possible to get a "Yes"/"No" response?

 

TOPICS
Acrobat SDK and JavaScript
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 11, 2020 Sep 11, 2020

Maybe the width and height of the icon object will give interesting info. Maybe not; perhaps there is always some kind of image assigned, even if it is blank.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 11, 2020 Sep 11, 2020

You can do it like this:

 

var buttonIcon = this.getField("Button3").buttonGetIcon();
try {
	var buttonIconStream = util.iconStreamFromIcon(buttonIcon);
	var streamLength = buttonIconStream.width*buttonIconStream.height;
	app.alert("Icon size: " + streamLength);
} catch (e) {
	app.alert("No icon found.");
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 11, 2020 Sep 11, 2020

Thanks try67! I'll be looking at "try" functionality.  Expect it will be very useful.

Code performing as needed:

var i = 0
for (var i=16;i<=112;i++)
if(i<70 || i>71){
{
s=i+"";
}
var buttonIcon = this.getField("Image"+s+"_af_image").buttonGetIcon();
try {
var buttonIconStream = util.iconStreamFromIcon(buttonIcon);
var streamLength = buttonIconStream.width*buttonIconStream.height;
// app.alert(streamLength);
}
catch (e) {
getField("FilePost"+s).value="";
getField("Text"+s).value="";
// app.alert("No icon found.");
}
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 11, 2020 Sep 11, 2020

You can comment out the streamLength variable, too.

The try-catch clause is used to catch run-time errors and handle them properly (instead of just existing the code immediately). The iconStreamFromIcon method throws such an error when you use it on an empty Icon object.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 11, 2020 Sep 11, 2020

THX!  You're an awesome resource.  The streamLength components are good to know anyway.  Added to my personal toolkit.

Can you send me a link to try-catch doc and the return codes for catch?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 11, 2020 Sep 11, 2020

try-catch is explained here: https://www.w3schools.com/js/js_errors.asp

 

The documentation of the iconStreamFromIcon method doesn't actually mention that it throws an error when the Icon object is empty. I found that out myself and then used that information to catch the error and handle it. This is the error message you get without the try-catch clause:

 

RaiseError: Expected a dict object.
Util.iconStreamFromIcon:2:Console undefined:Exec
===> Expected a dict object.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 11, 2020 Sep 11, 2020

Thanks again try67.  Will be reviewing the doc.

Nothing beats the significant hands-on you have.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 14, 2020 Sep 14, 2020

I'm using the following script to set any one of over 100 images I have on a form. 

** Thanks try67! **

 

I want to conditionally "clear image" instead of assigning an image, without using a blank file.  Is this do-able?

 

s = event.target.name;
s1 = s.substr(5,s.length-14);
FP = "FilePost"+s1
//app.alert(FP);

var cRtn = app.response (
{
cQuestion:"Paste the Image File Name",
cTitle:"Assign Image",
//bPassword:true,
//cDefault: global.cLastPswd,
cLabel:"File Name:"});
if(cRtn && cRtn.length) {
}
else app.alert("File name invalid or not present");

var strDIPath = "/" + cRtn.replace(/\:?\\/g,"/");
var strDIPath = strDIPath.replace(/"/g,"");

var cRtn = strDIPath;

event.target.buttonImportIcon(cRtn);
getField(FP).value=cRtn;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 14, 2020 Sep 14, 2020

No, a script can't clear an field's image, unfortunately.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 14, 2020 Sep 14, 2020
LATEST

Sounds to me like an easy hole to plug.  Oh well.  Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines