• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Oct 25, 2018 Oct 25, 2018

Copy link to clipboard

Copied

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?

  1. //DESCRIPTION:Report Bad Resolutions for a New Year 
  2. // No Guarantees, Ltd. Use at your own risk. 
  3. // Jongware, 05-Feb-2010 
  4. // Minimum dpi allowed: 
  5. var minimumValue = 300; 
  6. // Alert when x/y scaling is off by this much percents: 
  7. var percentageScaling = 1; 
  8. var lowResList = new Array; 
  9. for (aGraphic=0; aGraphic<app.activeDocument.allGraphics.length; aGraphic++) 
  10. oneGraphic = app.activeDocument.allGraphics[aGraphic]; 
  11. try { 
  12.   xres = oneGraphic.effectivePpi[0]; 
  13.   yres = oneGraphic.effectivePpi[1]; 
  14.   if (xres < minimumValue || yres < minimumValue) 
  15.    lowResList.push (oneGraphic); 
  16.   else 
  17.   { 
  18.    if (xres < yres) 
  19.     scaling = 100*yres/xres; 
  20.    else 
  21.     scaling = 100*xres/yres; 
  22.    if (scaling > 100+percentageScaling) 
  23.     lowResList.push (oneGraphic); 
  24.   } 
  25. } catch (_) {} 
  26. if (lowResList.length > 0
  27. doc = app.documents.add(); 
  28. frame = doc.textFrames.add({geometricBounds:[0,0,doc.documentPreferences.pageHeight, doc.documentPreferences.pageWidth]}); 
  29. txt = ''; 
  30. for (i=0; i<lowResList.length; i++) 
  31.   pg = ultimateParent (lowResList); 
  32.   txt = txt+"File: "+lowResList.itemLink.name; 
  33.   if (pg.parent instanceof(MasterSpread)) 
  34.    txt = txt+' on Master spread '+pg.name; 
  35.   else 
  36.    if (pg instanceof(Spread)) 
  37.    { 
  38.     txt = txt+' on clipboard of pg '+pg.pages[0].name; 
  39.     for (j=1; j<pg.pages.length; j++) 
  40.      txt += '-'+pg.pages.name; 
  41.    } else 
  42.     txt = txt+' on pg '+pg.name; 
  43.   txt = txt+' has xres: '+lowResList.effectivePpi[0]+', yres: '+lowResList.effectivePpi[1]+'\n'; 
  44. frame.contents = txt; 
  45. } else 
  46. alert ("No images have a resolution less than "+minimumValue+" dpi"); 
  47.  
  48. function ultimateParent(obj) 
  49. while (1
  50.   obj = obj.parent; 
  51.   if (obj.constructor.name == "Page"
  52.    break; 
  53.   if (obj.constructor.name == "Character"
  54.    obj = obj.parentTextFrames[0]; 
  55.   if (obj.constructor.name == "Spread" || obj.constructor.name == "MasterSpread"
  56.    break; 
  57. return obj; 
TOPICS
Scripting

Views

2.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 26, 2018 Oct 26, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 26, 2018 Oct 26, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 29, 2018 Oct 29, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 30, 2018 Oct 30, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2018 Oct 30, 2018

Copy link to clipboard

Copied

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.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);   

      txt = txt+"File: "+lowResList.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.name;   

       } else   

        txt = txt+' on pg '+pg.name;   

      txt = txt+' has xres: '+lowResList.effectivePpi[0]+', yres: '+lowResList.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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 30, 2018 Oct 30, 2018

Copy link to clipboard

Copied

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;

var docStatus = docRef.status;

if (docStatus == BookContentStatus.DOCUMENT_IS_OPEN) {

    var docName = bookFiles.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;

       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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 31, 2018 Oct 31, 2018

Copy link to clipboard

Copied

Hi Hopkins,

How can I fix this error in your translated code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2018 Oct 31, 2018

Copy link to clipboard

Copied

Hi,

for certain types of graphics property effectivePpi is not available.

Like placed AI files or PDFs…

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 31, 2018 Oct 31, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 24, 2018 Nov 24, 2018

Copy link to clipboard

Copied

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

Don't need try/catch. Just check the object constructor... let us assume object is named graphic...

if (graphic instanceof Image) {

   ppi = graphic.effectivePpi;

} else {

    // 'graphic' is not raster (not an 'Image').

}

William Campbell

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 31, 2018 Oct 31, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 24, 2018 Nov 24, 2018

Copy link to clipboard

Copied

Try this free script. Select book doc, choose to make a CSV and open in Excel, sort by row PPI and you can see all that fall below whatever value you're after.

https://www.marspremedia.com/software/indesign/links-report

William Campbell

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 25, 2018 Nov 25, 2018

Copy link to clipboard

Copied

Why do you need scripting for this? Why do you not simple use Indesign's preflight to check your book?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 25, 2018 Nov 25, 2018

Copy link to clipboard

Copied

LATEST

Right.

Preflight will even catch more:

Image data in placed PDFs or AIs, also in placed EPS files.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines