8 Replies Latest reply on Jun 27, 2011 5:45 AM by S.M. Arafat

    How can I extract images in all the pages

    S.M. Arafat

      Hi,

      I tried to extract images of all the pages in an indesign document but I couldn't. The script I used is able to extract images of only the first page of the document. Can anyone please help?

       

      Looking at the script, it seems like it should be able to extract images of all the pages, but actually it doesn't. I don't want document.export, because it is time consuming. Following is the script I used. Am I missing anything?

       

       

      function decode64(input) {
          var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
          var output = "";
          var chr1, chr2, chr3 = "";
          var enc1, enc2, enc3, enc4 = "";
          var i = 0;
          input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
          do {
              enc1 = keyStr.indexOf(input.charAt(i++));
              enc2 = keyStr.indexOf(input.charAt(i++));
              enc3 = keyStr.indexOf(input.charAt(i++));
              enc4 = keyStr.indexOf(input.charAt(i++));
              chr1 = (enc1 << 2) | (enc2 >> 4);
              chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
              chr3 = ((enc3 & 3) << 6) | enc4;
              output = output + String.fromCharCode(chr1);
              if (enc3 != 64) {output = output + String.fromCharCode(chr2);}
              if (enc4 != 64) {output = output + String.fromCharCode(chr3);}
              chr1 = chr2 = chr3 = "";
              enc1 = enc2 = enc3 = enc4 = "";
          } while (i < input.length);
          return output;
      }
      
      
      // XMP namespace where preview is saved
      var XMPnamespace = "http://ns.adobe.com/xap/1.0/";
      var myPreviews = Array();
      
      var docName = app.activeDocument.name;
      // extract just file name without extension from document name
      docName = docName.replace(/.[^.]+$/,'');
      
      // count number of previews in both XML nodes
      thumbCnt = app.activeDocument.metadataPreferences.countContainer(XMPnamespace,"Thumbnails");
      pagInfCnt = app.activeDocument.metadataPreferences.countContainer(XMPnamespace,"PageInfo");
      
      var pagePrevCount, XMPnode;
      // check and set retrieved values if(thumbCnt != 0){     pagePrevCnt = thumbCnt;     XMPnode = "Thumbnails"; }else if(pagInfCnt != 0){     pagePrevCnt = pagInfCnt;     XMPnode = "PageInfo"; }else{     alert("No Data saved");     exit(); } // loop through available nodes, and retrieve data for(var i = 1; i <= pagePrevCnt; i++){     var myTemp = app.activeDocument.metadataPreferences.getProperty(XMPnamespace, XMPnode+"[" + i + "]/xapGImg:image");     myTemp = myTemp.replace("/*missing*/","\n");     myPreviews.push(myTemp); } // loop through previews and save them to files for(var i = 0; i < myPreviews.length; i++){     myPreview = decode64(myPreviews[i]);     myOutput = new File ('/c/Preview for ' + docName + ' No. ' + (i + 1) + '.jpeg');     myOutput.encoding = 'binary';     myOutput.open ('w');     myOutput.write (myPreview);     myOutput.close(); }

      Best Regards,
      -Arafat