7 Replies Latest reply on Feb 16, 2013 6:08 PM by Giordano Galli

    Accessing the xmpMM:History property in InDesign CS4

    Giordano Galli

      Hello everyone

       

      I apologize in advance for the naivety of my questions, this is brand new stuff to me.

       

      After reading several relevant discussions on the forum and following the links to Marijan Tompa's articles on the subject I'm trying to access the value of the xmpMM:History property in the active document in InDesign CS4 using this code:

       

      if ( !ExternalObject.AdobeXMPScript )

                {

                          try{ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');}

                          catch (e){alert('Unable to load the AdobeXMPScript library!'); return false;}

                }

      var myDocXMP = app.activeDocument.metadataPreferences;

      var destNamespace = "http://ns.adobe.com/xap/1.0/mm/";

      alert("Value= <" + myDocXMP.getProperty(destNamespace, 'History') + ">");

       

      The result is "Value<>".

       

       

      If I try instead

       

      destNamespace = "http://ns.adobe.com/xap/1.0/"

      alert("Value= <" + myDocXMP.getProperty(destNamespace, 'CreatorTool') + ">");

       

      I get what I think is the correct result, ie "Value=<Adobe InDesign 6.0>".

       

      My question is whether the xmpMM:History property can be read and, if this is the case, what must be changed in the syntax I'm using.

       

      Thank you very much for your attention and patience.

       

       

      Giordano

        • 1. Re: Accessing the xmpMM:History property in InDesign CS4
          -hans- Level 4

          Hi,

           

          'History' is a Array / Sequence in the xmp.

           

          Basic use:

          var myDocXMP = app.activeDocument.metadataPreferences;

          alert("Value= <" + myDocXMP.getProperty(XMPConst.NS_XMP_MM, 'History[1]/stEvt:when') + ">"); //firstItem

          alert("Value= <" + myDocXMP.getProperty(XMPConst.NS_XMP_MM, 'History[2]/stEvt:when') + ">"); //secondItem

           

          Other values except of when: parseType, action, instanceID, when, softwareAgent, changed

           

          If you want to use AdobeXMPScript you've got to load xmpData from file – guess.

          You'll be able then to count the HistoryArray and target a specific item.

          This is described here: http://indisnip.wordpress.com/2010/08/17/extract-metadata-with-adobe-xmp-part-2/

          • 2. Re: Accessing the xmpMM:History property in InDesign CS4
            Giordano Galli Level 1

            Hi

             

            Thank you very much for your reply, I now understand that the problem had to do with the data structure.

             

            I'm now having a hard time understanding in which situations it is impossible to refer to the active document and it is necessary to load its xmp data from the document's file. I'd really appreciate if anyone could point me to an explanation of this matter.

             

            I'd also be thankful if somebody told me whether the ' History' array can be simply voided (this is in fact my present goal).

             

            Thank you again.

             

             

            Giordano

            • 3. Re: Accessing the xmpMM:History property in InDesign CS4
              -hans- Level 4

              Hi,

               

              this should delete the whole history, give it a try:

               

              //active Document

              var currDoc = app.activeDocument;

              //path to ...

              var fullName = currDoc.fullName;

              //close it to delete history metadata

              currDoc.close(SaveOptions.YES);

              //clean up history ...

              voidHistory(fullName);

              //reopen

              app.open(fullName);

               

                //

              function voidHistory(fileObject){

              if(loadXMPLibrary()){

                      var myFile = fileObject;

                      xmpFile = new XMPFile(myFile.fsName, XMPConst.NS_XMP_MM, XMPConst.OPEN_FOR_UPDATE);

                      var myXmp = xmpFile.getXMP();

                     

                      var count = myXmp.countArrayItems(XMPConst.NS_XMP_MM, "History") +1;

                      //here part to delete every arrayitem of history

                      while(count--){

                          if(count == 0){break;}

                          myXmp.deleteArrayItem(XMPConst.NS_XMP_MM, "History", count)

                          }

                     

                myXmp.serializeToArray();

                 //bring new metadata to file

                   if (xmpFile.canPutXMP(myXmp)) {

                       xmpFile.putXMP(myXmp);  

                       }

               

                      xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);

              unloadXMPLibrary();   

               

              }

              }

               

                  function loadXMPLibrary(){

                      if ( !ExternalObject.AdobeXMPScript ){

                          try{ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');}

                          catch (e){alert('Unable to load the AdobeXMPScript library!'); return false;}

                      }

                      return true;

                  }

               

              function unloadXMPLibrary(){

                      if( ExternalObject.AdobeXMPScript ){

                          try{ExternalObject.AdobeXMPScript.unload(); ExternalObject.AdobeXMPScript = undefined;}

                          catch (e){alert('Unable to unload the AdobeXMPScript library!');}

                      }

                  }

              Never done it before, but works here ...

               

              Hans-Gerd Claßen

              1 person found this helpful
              • 4. Re: Accessing the xmpMM:History property in InDesign CS4
                Giordano Galli Level 1

                Hi

                 

                Thank you so much!

                 

                When I read your reply I had just finished putting together a 101 version of the same code, mainly grabbed from snippets I found.

                 

                I do layout work and I'm trying to solve a problem that has bothered us for a long time. I don't know whether newer versions of InDesign solved it but CS4, which we are stuck with, often blows up pdfs that then have to be optimized in Acrobat.

                The unwanted content seem to almost entirely comprise entries from 'xmpMM:History', which can easily account for a 5-10 fold increase when InDesign documents get used again and again (eg magazines and book series).

                I found a solution involving a round trip idml archive I purged in Oxygen but this method has obvious drawbacks so I thought I'd try the scripting way.

                 

                If you don't mind I'll ask about a detail that has probably more to do with general javascript programming. In my uninformed attempt I came up with

                 

                while (myXmp.getProperty(XMPConst.NS_XMP_MM,"History[1]") != undefined)

                     {

                          myXmp.deleteProperty(XMPConst.NS_XMP_MM,"History[1]");

                     }

                 

                It seems to work but I wonder whether it is unsafe or inefficient.

                 

                Thank you again.

                  

                 

                Giordano

                • 5. Re: Accessing the xmpMM:History property in InDesign CS4
                  -hans- Level 4

                  Hi,

                   

                            myXmp.deleteProperty(XMPConst.NS_XMP_MM,"History[1]");

                   

                  does not work on my machines.

                   

                  Instead of while you could use if as it should be done only once.

                   

                  That's why I used deleteArrayItem() in my code above as [1] is the first item in the xmp-array.

                   

                  If it works on your machine¿(I'm really not shure on this !), then at least remember you've got to repeat with history[1] to history[x].

                   

                  Did you try my code?

                  1 person found this helpful
                  • 6. Re: Accessing the xmpMM:History property in InDesign CS4
                    David W. Goodrich Level 3

                    I tried your code, Hans, and it seems to work fine for me (IDCS4 under 64-bit Win7).  Thank you very much.

                     

                    There are a number of reasons for stripping out some XMP multimedia metadata: I was startled to find, like Giordano, that IDCS4 templates were preserving a lot of useless material and bloating my PDFs.  The excess baggage also prevents compliance with PDF/A, as Dave Merchant describes over on the Acrobat forum.  Versions of Acrobat before XI could not strip the junk out, as he details in his blog, where he also provides a script to purge the material.  As I wrote over on the ID forum late last year, I took to editing INX files exported from my IDCS4 templates, and zapping the XMP categories named in Dave's JS script: INX are simpler than IDML, and for me to do this by hand the process was not much slower than going down the hall and firing up the IDCS5.5 machine for round-trip cleansing.  Your ID JSX doesn't zap all of Dave's categories, so I think I'll stick with your more conservative approach until I figure out the consequences for a work file of stripping out, say, xmpMM:Manifest.

                     

                    Thanks again,

                    David

                    1 person found this helpful
                    • 7. Re: Accessing the xmpMM:History property in InDesign CS4
                      Giordano Galli Level 1

                      Hello Hans

                      -hans- wrote:

                       

                      Did you try my code?

                       

                      Sure, I'm using it and it works fine. Thank you!

                       

                       

                      Giordano