10 Replies Latest reply on Oct 31, 2018 7:36 AM by DavidMWE

    Is it possible to find all images below 300dpi in a book document?

    manilap94829696

      Hi there, I'm hoping this is a quick question. I've had a look on google but to no avail.

      This script run in open document only to search and plug images below 300dpi.

       

      Is it possible to run this script in Book File?

       

      //DESCRIPTION:Report Bad Resolutions for a New Year  
      // No Guarantees, Ltd. Use at your own risk.  
      // Jongware, 05-Feb-2010  
      // Minimum dpi allowed:  
      var minimumValue = 300;  
      // Alert when x/y scaling is off by this much percents:  
      var percentageScaling = 1;  
      var lowResList = new Array;  
      for (aGraphic=0; aGraphic<app.activeDocument.allGraphics.length; aGraphic++)  
      {  
       oneGraphic = app.activeDocument.allGraphics[aGraphic];  
       try {  
        xres = oneGraphic.effectivePpi[0];  
        yres = oneGraphic.effectivePpi[1];  
        if (xres < minimumValue || yres < minimumValue)  
         lowResList.push (oneGraphic);  
        else  
        {  
         if (xres < yres)  
          scaling = 100*yres/xres;  
         else  
          scaling = 100*xres/yres;  
         if (scaling > 100+percentageScaling)  
          lowResList.push (oneGraphic);  
        }  
       } catch (_) {}  
      }  
      if (lowResList.length > 0)  
      {  
       doc = app.documents.add();  
       frame = doc.textFrames.add({geometricBounds:[0,0,doc.documentPreferences.pageHeight, doc.documentPreferences.pageWidth]});  
       txt = '';  
       for (i=0; i<lowResList.length; i++)  
       {  
        pg = ultimateParent (lowResList[i]);  
        txt = txt+"File: "+lowResList[i].itemLink.name;  
        if (pg.parent instanceof(MasterSpread))  
         txt = txt+' on Master spread '+pg.name;  
        else  
         if (pg instanceof(Spread))  
         {  
          txt = txt+' on clipboard of pg '+pg.pages[0].name;  
          for (j=1; j<pg.pages.length; j++)  
           txt += '-'+pg.pages[j].name;  
         } else  
          txt = txt+' on pg '+pg.name;  
        txt = txt+' has xres: '+lowResList[i].effectivePpi[0]+', yres: '+lowResList[i].effectivePpi[1]+'\n';  
       }  
       frame.contents = txt;  
      } else  
       alert ("No images have a resolution less than "+minimumValue+" dpi");  
        
      function ultimateParent(obj)  
      {  
       while (1)  
       {  
        obj = obj.parent;  
        if (obj.constructor.name == "Page")  
         break;  
        if (obj.constructor.name == "Character")  
         obj = obj.parentTextFrames[0];  
        if (obj.constructor.name == "Spread" || obj.constructor.name == "MasterSpread")  
         break;  
       }  
       return obj;  
      }  
      
      
        • 1. Re: Is it possible to find all images below 300dpi in a book document?
          S Hopkins Adobe Community Professional

          Below is a sample demonstration script written for AppleScript that does what you are looking for. It produces a list of the names of graphics where effective PPI is less than 299 or greater than 301 for both the x and y parameters. This can give you some ideas for your ExtendScript.

           

           

          tell application "Adobe InDesign CC 2018"

            set bookCount to count of books

            if bookCount = 0 then

            set fileRef to choose file

            set bookRef to open bookFile

            else

            set bookRef to book 1

            end if

            set badList to {}

            set bookFiles to book contents of bookRef

            with timeout of 500 seconds

            repeat with i from 1 to length of bookFiles

            set thisDoc to item i of bookFiles

            set docStatus to status of thisDoc

            if docStatus is not "document is open" then

            set docPath to full name of thisDoc

            set docRef to open file docPath

            else

            set docName to name of thisDoc

            set docRef to document docName

            end if

            tell docRef

            set graphicList to all graphics

            end tell

            repeat with j from 1 to length of graphicList

            set thisGraphic to item j of graphicList

            set thisPPi to effective ppi of thisGraphic

            set thisTest to 0

            if item 1 of thisPPi < 299 or item 2 of thisPPi > 301 then

            set thisTest to thisTest + 1

            end if

            if item 2 of thisPPi < 209 or item 2 of thisPPi > 301 then

            set thisTest to thisTest + 1

            end if

            if thisTest > 0 then

            set end of badList to name of item link of thisGraphic

            end if

            end repeat

            end repeat

            end timeout

          end tell

          • 2. Re: Is it possible to find all images below 300dpi in a book document?
            manilap94829696 Level 1

            Thanks Hopkins... but I'm not good in translating/reading AppleScript

            • 3. Re: Is it possible to find all images below 300dpi in a book document?
              BarlaeDC Adobe Community Professional

              Hi,

               

              You should be able to get the bookContents and then loop through each entry, making sure it is open in InDesign then run your code on it.

              // assuming only one book open.

              var myBook = app.books[0];

              var allInddFiles = myBook.bookContents;

               

              for ( var i = 0; i < allInddFiles.length; i++)

              {

                   var curDoc = app.open ( allInddFiles[i].fullName )

               

                   // your code here, with changes to cope with using the curDoc variable from above

               

                   // close your doc when you are finished

                   curDoc.close ( SaveOptions.NO);

              }

               

              Hope this helps

               

              Malcolm

              • 4. Re: Is it possible to find all images below 300dpi in a book document?
                manilap94829696 Level 1

                Hi Malcolm,

                 

                I've tried your suggestion but the outcome will open every document create list then closed then open another one create list then close again until the last indesign in a book. Is there a way that it will run first throughout the book then create only one list of images.

                 

                Many thanks.

                 

                -ryu

                • 5. Re: Is it possible to find all images below 300dpi in a book document?
                  BarlaeDC Adobe Community Professional

                  Hi Ryu,

                   

                  My code doesn't handle the creation of the list document at all, but if you want all images to be listed in one document, create that document before you start the loop and always write to it in the code.

                   

                  //Something like

                  var doc = app.documents.add();
                  for ( var i = 0; i < allInddFiles.length; i++)
                  {
                       var curDoc = app.open ( allInddFiles[i].fullName )
                  
                        //DESCRIPTION:Report Bad Resolutions for a New Year    
                      // No Guarantees, Ltd. Use at your own risk.    
                      // Jongware, 05-Feb-2010    
                      // Minimum dpi allowed:    
                      var minimumValue = 300;    
                      // Alert when x/y scaling is off by this much percents:    
                      var percentageScaling = 1;    
                      var lowResList = new Array;    
                      for (aGraphic=0; aGraphic<app.activeDocument.allGraphics.length; aGraphic++)    
                      {    
                       oneGraphic = app.activeDocument.allGraphics[aGraphic];    
                       try {    
                        xres = oneGraphic.effectivePpi[0];    
                        yres = oneGraphic.effectivePpi[1];    
                        if (xres < minimumValue || yres < minimumValue)    
                         lowResList.push (oneGraphic);    
                        else    
                        {    
                         if (xres < yres)    
                          scaling = 100*yres/xres;    
                         else    
                          scaling = 100*xres/yres;    
                         if (scaling > 100+percentageScaling)    
                          lowResList.push (oneGraphic);    
                        }    
                       } catch (_) {}    
                      }    
                      if (lowResList.length > 0)    
                      {    
                           
                       frame = doc.textFrames.add({geometricBounds:[0,0,doc.documentPreferences.pageHeight, doc.documentPreferences.pageWidth]});    
                       txt = '';    
                       for (i=0; i<lowResList.length; i++)    
                       {    
                        pg = ultimateParent (lowResList[i]);    
                        txt = txt+"File: "+lowResList[i].itemLink.name;    
                        if (pg.parent instanceof(MasterSpread))    
                         txt = txt+' on Master spread '+pg.name;    
                        else    
                         if (pg instanceof(Spread))    
                         {    
                          txt = txt+' on clipboard of pg '+pg.pages[0].name;    
                          for (j=1; j<pg.pages.length; j++)    
                           txt += '-'+pg.pages[j].name;    
                         } else    
                          txt = txt+' on pg '+pg.name;    
                        txt = txt+' has xres: '+lowResList[i].effectivePpi[0]+', yres: '+lowResList[i].effectivePpi[1]+'\n';    
                       }    
                       frame.contents = txt;    
                      } else    
                       alert ("No images have a resolution less than "+minimumValue+" dpi");    
                          
                      function ultimateParent(obj)    
                      {    
                       while (1)    
                       {    
                        obj = obj.parent;    
                        if (obj.constructor.name == "Page")    
                         break;    
                        if (obj.constructor.name == "Character")    
                         obj = obj.parentTextFrames[0];    
                        if (obj.constructor.name == "Spread" || obj.constructor.name == "MasterSpread")    
                         break;    
                       }    
                       return obj;    
                      }    
                  
                       curDoc.close ( SaveOptions.NO);
                  
                  }
                  

                  Hope this helps

                   

                  Malcolm

                  • 6. Re: Is it possible to find all images below 300dpi in a book document?
                    S Hopkins Adobe Community Professional

                    Sorry, but I already had an AppleScript. Here is the script translated for JavaScript. It's coarse, I know but pretty much line for line. That way you can see how easy it is to translate from AppleScript to JavaScript and vice-versa. Script is not thoroughly tested either.

                    var appRef = app;

                    var bookCount = appRef.books.count();

                    if (bookCount == 0) {

                      var fileRef = File.openDialog("Select inDesign book file");

                      var bookRef = appRef.open(File(fileRef));

                    } else {

                      var bookRef = appRef.books.item(0);

                    }

                    var badList = [];

                    var bookFiles = bookRef.bookContents;

                    for (var i = 1; i < bookFiles.length; i++) {

                    var docRef = bookFiles[i];

                    var docStatus = docRef.status;

                    if (docStatus == BookContentStatus.DOCUMENT_IS_OPEN) {

                        var docName = bookFiles[i].name;

                        docRef = appRef.documents.itemByName(docName);

                      } else {

                          var docPath = docRef.fullName;

                          docRef = appRef.open(File(docPath));

                       }

                       var graphicList = docRef.allGraphics;

                       for (var j = 0; j < graphicList.length; j++) {

                           var thisTest = 0;

                           var thisGraphic = graphicList[j];

                           var thisPpi = thisGraphic.effectivePpi;

                           if (thisPpi[0]< 299 || thisPpi[0]> 301) {

                               thisTest += 1;

                           }

                          if (thisPpi[1] < 299 || thisPpi[1]> 301) {

                               thisTest += 1;

                           }

                       if (thisTest >0) {

                           badList.push(thisGraphic.itemLink.name);

                        }

                    }//ends repeat j

                    } //ends repeat i

                    badList;

                    • 7. Re: Is it possible to find all images below 300dpi in a book document?
                      manilap94829696 Level 1

                      Hi Hopkins,

                      How can I fix this error in your translated code.

                      • 8. Re: Is it possible to find all images below 300dpi in a book document?
                        Laubender Adobe Community Professional & MVP

                        Hi,

                        for certain types of graphics property effectivePpi is not available.

                        Like placed AI files or PDFs…

                         

                        Regards,
                        Uwe

                        • 9. Re: Is it possible to find all images below 300dpi in a book document?
                          [Jongware] Most Valuable Participant

                          Which is why that part is wrapped in my script in a try...catch block.

                          • 10. Re: Is it possible to find all images below 300dpi in a book document?
                            DavidMWE Level 2

                            If you want to skip the code, just download a full working demo of FlightCheck. Drag-and-drop your InDesign file onto it. Look at the main window and see the "images" section. There you can sort by DPI and many other factors.

                             

                            Friendly Regards,

                            David Dilling

                            Markzware