fctallantjr
asked on
Can't Access Icon Object, Name Property in PDF Document
Why can't I access Icon Object, Name Property in PDF Document ?
The Acrobat 8 (and 7) javascript reference document gives this example code:
Example 1
Report the number of named icons in the current document.
if (this.icons == null)
console.println("No named icons in this doc");
else
console.println("There are " + this.icons.length
+ " named icons in this doc");
Example 2
List all named icons the current document.
for (var i = 0; i < this.icons.length; i++) {
console.println("icon[" + i + "]=" + this.icons[i].name);
}
Using this code syntax, I can get javascript to tell me the value in "this.icons.length", but it will not tell me "this.ocons[i].name".
When referencing a document that has more than one ocon object, as indicated by the value returned by the length property,
the reference to the name property gives the following error:
Acrobat JavaScript Debugger Functions Version 7.0
Acrobat Database Connectivity Built-in Functions Version 8.0
Acrobat EScript Built-in Functions Version 8.0
Acrobat Annotations / Collaboration Built-in Functions Version 8.0
Acrobat Annotations / Collaboration Built-in Wizard Functions Version 8.0
Acrobat Multimedia Version 8.0
Acrobat SOAP 8.0
TypeError: this.icons[i] has no properties
12:Field:Mouse Up
TypeError: this.icons[i] has no properties
12:Field:Mouse Up
Here is my specific code:
var strFieldsInfo='';
if (this.icons == null)
strFieldsInfo="No named icons in this doc";
else
for (var i = 0; i < this.icons.length; i++) {
console.println("icon[" + i + "]=" + this.icons[i].name);
}
The Acrobat 8 (and 7) javascript reference document gives this example code:
Example 1
Report the number of named icons in the current document.
if (this.icons == null)
console.println("No named icons in this doc");
else
console.println("There are " + this.icons.length
+ " named icons in this doc");
Example 2
List all named icons the current document.
for (var i = 0; i < this.icons.length; i++) {
console.println("icon[" + i + "]=" + this.icons[i].name);
}
Using this code syntax, I can get javascript to tell me the value in "this.icons.length", but it will not tell me "this.ocons[i].name".
When referencing a document that has more than one ocon object, as indicated by the value returned by the length property,
the reference to the name property gives the following error:
Acrobat JavaScript Debugger Functions Version 7.0
Acrobat Database Connectivity Built-in Functions Version 8.0
Acrobat EScript Built-in Functions Version 8.0
Acrobat Annotations / Collaboration Built-in Functions Version 8.0
Acrobat Annotations / Collaboration Built-in Wizard Functions Version 8.0
Acrobat Multimedia Version 8.0
Acrobat SOAP 8.0
TypeError: this.icons[i] has no properties
12:Field:Mouse Up
TypeError: this.icons[i] has no properties
12:Field:Mouse Up
Here is my specific code:
var strFieldsInfo='';
if (this.icons == null)
strFieldsInfo="No named icons in this doc";
else
for (var i = 0; i < this.icons.length; i++) {
console.println("icon[" + i + "]=" + this.icons[i].name);
}
ASKER
How am I using the code?
Yep, it's executing in a mouse click event of a button. So the problem is a security restriction on doing this?
Yep, it's executing in a mouse click event of a button. So the problem is a security restriction on doing this?
Is there anything else you are doing? Using the same code in a button event also works for me. There should not be any security restrictions around the icon object (at least not according to the documentation).
Can you provide the PDF file that shows the problem?
ASKER
File emailed to khkremer.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The file did indeed contain null values for some the icons in the icon object. Knowing this lets me go forward, so Kudos to Kremer.
There was error in the code that attempted to insert the icons in the first place, and this was what caused the NULL values.
There was error in the code that attempted to insert the icons in the first place, and this was what caused the NULL values.
I created a new elements in the PDF file with these two lines (for two different button named and icon ids):
var f = this.getField("Button1");
this.addIcon("myButtonIcon
Once I run the code from the end of your question in the JavaScript debugger, it correctly showed the two names:
var strFieldsInfo='';
if (this.icons == null)
strFieldsInfo="No named icons in this doc";
else
for (var i = 0; i < this.icons.length; i++) {
console.println("icon[" + i + "]=" + this.icons[i].name);
}
icon[0]=myButtonIcon
icon[1]=myButtonIcon2
undefined
It looks like you are trying to do this from a mouse event handler. Can you please describe exactly how you are using the code.