Solved

Can't Access Icon Object, Name Property in PDF Document

Posted on 2006-11-03
7
406 Views
Last Modified: 2010-05-18
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);
     }


0
Comment
Question by:fctallantjr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17880586
It works for me. I used both Acrobat 7 and 8 to verify that your code (which as you indicate is from the AcroJS guide) does work.

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", f.buttonGetIcon());

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.
0
 

Author Comment

by:fctallantjr
ID: 17881558
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?
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17881631
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).
0
[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 17888540
Can you provide the PDF file that shows the problem?
0
 

Author Comment

by:fctallantjr
ID: 17888813
File emailed to khkremer.
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 500 total points
ID: 17889124
I don't know what you did with that file, but you ended up with some of the icons set to NULL. Usually, when you remove an icon with the this.removeIcon() method, the whole icon list gets adjusted, and you don't end up with "holes" in the list. In your case, you somehow did end up with these holes. If you use exception handling, you can still get the correctly named icons:

var strFieldsInfo='';
     
if (this.icons == null)
    strFieldsInfo="No named icons in this doc";
else
{      
    for (var i = 0; i < this.icons.length; i++)
    {
        try {
            console.println("icon[" + i + "]=" + this.icons[i].name);
        }
        catch (e)
        {
           console.println(e);  // comment this line if you don't want the exception message
        }
    }
}

0
 

Author Comment

by:fctallantjr
ID: 17930362
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.  
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe INTRODUCTION This Article is a follow-up to the Article entitled How To Rename-Move a Batch of PDF Files Based o…
PaperPort is a popular document imaging/management product from Nuance Communications (http://www.nuance.com/). It is in widespread use by both individuals (http://www.nuance.com/for-individuals/by-product/paperport/index.htm) and businesses (http:/…
In this third video of the Xpdf series, we discuss and demonstrate the PDFtoText utility, which converts PDF files into plain text files. Download and install the software.: You may have already downloaded and installed the Xpdf tools while watching…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question