6 Replies Latest reply on Jan 13, 2015 12:35 PM by MadMac55

    Get the associated text of an image

    x51398 Level 1

      Hi,

       

      in preparation of exporting an tagged pdf, I use the anchor tool to associate the description text with the corresponding image.

      Now I'm looking for a option to set the ALT text (object export options) of the image from the previous linked text.

      I tried it with the AnchoredObjectSetting properties of the image parent, but unfortunately without success - I can't get a reference to the linked text.

       

      var page = myDoc.pages[0];
      var images = page.allGraphics;
      for(var z = 0; z < images.length; z++){
           var image = images[z];
           var imageParent = image.parent; //-> RectAngle
           //here I need to get the reference to the anchored description TextFrame - but how?
           //I tried
           var test = imageParent.anchoredObjectSettings; //but in this object I could not found the requestet informations
      }
      

       

      Is there a way to do this?

       

      Thank You, regards

      Sebastian

        • 1. Re: Get the associated text of an image
          Laubender Adobe Community Professional & MVP

          @Sebastian – the parent of the parent of the graphic is a character.

          The anchor.

           

          And the parentStory of that character seems to be the text that you are looking for.

          The contents of that parentStory is a string.

           

          So the following should work:

           

          var myDescriptionAsString = myAnchoredGraphic.parent.parent.parentStory.contents;
          

           

          Note: The anchor character itself (as string) is also part of the result.

          Uwe

          • 2. Re: Re: Get the associated text of an image
            Laubender Adobe Community Professional & MVP

            But of course you have to check first, if the parent of the parent is indeed a Character.

             

            if(myGraphic.parent.parent.constructor.name === "Character"){doYourThing()};
            

             

            Uwe

            • 3. Re: Get the associated text of an image
              x51398 Level 1

              @Laubender

               

              Thank You so much - works fine! I'm happy

               

              Sebastian

              • 4. Re: Get the associated text of an image
                MadMac55 Level 1

                Very interesting.  What did your final script look like?

                • 5. Re: Re: Get the associated text of an image
                  x51398 Level 1

                  Hi,

                   

                  var myDoc = app.activeDocument;
                  for(var i = 0; i < myDoc.pages.length; i++){
                    var page = myDoc.pages[i];
                  
                    // add alt text to image from linked description text /////////////////////////////////////////////////////////////
                    var images = page.allGraphics;
                    for(var z = 0; z < images.length; z++){
                        var image = images[z];
                  
                         //get anchor
                         var anchor = image.parent.parent;
                         if(anchor.constructor.name === "Character"){
                              if(anchor.parentStory.isValid){
                                   //get text
                                   var descText = anchor.parentStory.contents;
                                   //remove anchor character
                                   //descText = descText.replace(/xxx/, "");// in extended toolkit console output you can see the anchor character - can't display them here
                                   //set alt text
                                   var exportOptions = image.parent.objectExportOptions;
                                   exportOptions.altTextSourceType = SourceType.SOURCE_CUSTOM;
                                   exportOptions.customAltText = altText;
                      
                              }
                         }
                    }
                    // /add alt text to image from linked description text /////////////////////////////////////////////////////////////
                  }
                  
                  
                  
                  

                   

                  Regards, Sebastian

                  • 6. Re: Get the associated text of an image
                    MadMac55 Level 1

                    This turned out very nice.   Great job, guys.