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

preflight scripting...

Explorer ,
Jun 20, 2018 Jun 20, 2018

Copy link to clipboard

Copied

i have combine a few scripts (thank you to those who have posted these bits) and created kind of a custom final collect for my organization except i need it to also run a very basic preflight so missing fonts or images will be flagged. I have tried to incorporate every preflight script i have been able to find but none seem to be working.

I have the script run and insert some info into the meta data, then it does a full collect and places the high res and low res PDFs into specific folders.

I obviously haven't written any of this but I have managed to get this completely functioning except for the preflight

here is what i have so far...How can i get it to check the status of the live preflight and give an alert/error if there are missing fonts or images?

I did not include any of my attempts at preflight because none have worked so far...

//===============                                                 metatagging                        ===============================

//-----document title and copyright---------

var myDocument = app.activeDocument;

with (myDocument.metadataPreferences){

    copyrightInfoURL = "ABC company"

    copyrightNotice = "© 2018 ABC company";

    copyrightStatus = CopyrightStatus.yes;

    documentTitle = myDocument.name.split(".indd")[0];

    }

//---------------------add document name-------------------------------

with (myDocument.metadataPreferences){

        documentTitle = myDocument.name.split(".indd")[0];

        }

//-----------------------images to keywords--------------------------//

app.activeDocument.metadataPreferences.keywords =

["ABC company"].concat(app.activeDocument.links.everyItem().name);

//-------------open file info dialog box---------------------

app.menuActions.itemByID(89092).invoke()

/

//=======================               packaging-                            ===================================-

// Package.jsx

//

// by Keith Gilbert

// gilbertconsulting.com

// blog.gilbertconsulting.com

//

// Revised 2018-01-15

//

#target indesign

main();

function main() {

  // Check to see whether any InDesign documents are open.

  // If no documents are open, display an error message.

  if (app.documents.length > 0) {

  var myDoc = app.activeDocument;

  ///Prompt the user for the folder

  var myTargetFolder = Folder.selectDialog("Select the folder in which to place the packaged files");

  if (myTargetFolder != null) {

  // Package the file

  myDoc.packageForPrint (

  to = myTargetFolder,

  copyingFonts = true,

  copyingLinkedGraphics = true,

  copyingProfiles = true,

  updatingGraphics = true,

  includingHiddenLayers = false,

  ignorePreflightErrors = true, // If this is set to false, and there are preflight errors, the script does nothing.

  creatingReport = false,

  includeIdml = false,

                includePdf = false,

  pdfStyle = "",

  useDocumentHyphenationExceptionsOnly = true, // Added to DOM in CC 2018

  versionComments = "",

  forceSave = true,

  )

  }

  else {

  return;

  }

  }

  else {

  // No documents are open, so display an error message.

  alert("No InDesign documents are open. Please open a document and try again.")

  }

}

//=================                     make the PDFs-              =====================================================

d = app.activeDocument;   

preset1 = app.pdfExportPresets.itemByName("press spreads and crops");   

preset2 = app.pdfExportPresets.itemByName("smallest size_spreads");       

if (!(preset1.isValid && preset2.isValid)){   

    alert("One of the presets does not exist. Please check spelling carefully.");   

    exit();   

mDocName = d.name.substr (0, d.name.lastIndexOf('.'));

mSourcePath = d.fullName.parent.toString();

mRootPath =mSourcePath.substr (0, mSourcePath.lastIndexOf('/'));

mTargetPath=mRootPath.concat('/Final_Art/LowRes_PDF_Final/');

  mNameWeb= mTargetPath.concat(mDocName,'_LOW.pdf');

mTargetPath=mRootPath.concat('/Final_Art/Print_PDF/');

mNamePrint = mTargetPath.concat(mDocName,'.pdf');   

if (!d.saved){   

    d.save;

}    

d.exportFile(ExportFormat.PDF_TYPE, new File(mNamePrint), false, preset1);   

d.exportFile(ExportFormat.PDF_TYPE, new File(mNameWeb), false, preset2);

TOPICS
Scripting

Views

3.5K

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

correct answers 1 Correct answer

Community Expert , Jun 25, 2018 Jun 25, 2018

Hi,

I have added the code into your script ( and cleaned up your script a wee bit, to make it easier to follow). hope this does what you want. let us know if you have any further questions.

#target indesign

// script wide variable

// we need a document for just about everything

// so declare it at the top

var curDoc = null

// as we need a document

// and we want to check fonts and images are correct,

// do that first

if (app.documents.length < 1)

{

    alert (" There are no active documents to work on")

   

...

Votes

Translate

Translate
Community Expert ,
Jun 21, 2018 Jun 21, 2018

Copy link to clipboard

Copied

Hi,

I am not sure you need to do full preflight, could you not just run something like

// get the status of links in a string, there are other status' you might need to check

// options are

//LinkStatus.NORMAL

//LinkStatus.LINK_OUT_OF_DATE

//LinkStatus.LINK_MISSING

//LinkStatus.LINK_EMBEDDED

//LinkStatus.LINK_INACCESSIBLE

var statusString = inddDoc.links.everyItem().status.toString();

if ( statusString.indexOf ("LINK_MISSING") !== -1)

{

   alert (" Document has missing images");

     // Stop the script

}

AND

// get that status of the fonts and check, you need to pick the options from below to make sure you catch what you want.

// options are

// FontStatus.INSTALLED

//FontStatus.NOT_AVAILABLE

//FontStatus.FAUXED

//FontStatus.SUBSTITUTED

//FontStatus.UNKNOWN

var fontStatus = inddDoc.fonts.everyItem().status.toString();

if  (( fontStatus.indexOf("NOT_AVAILABLE ") !== -1) || ( fontStatus.indexOF("SUBSTITUTED") !== -1 ))

{

     alert ("Document appears to have missing fonts"):

     // stop the script

}

Hope this helps

Malcolm

[Edited to remove incorrect string statements in fontStatus if ]

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
Explorer ,
Jun 22, 2018 Jun 22, 2018

Copy link to clipboard

Copied

i so appreciate your help.....but

I'm not sure how to insert your snippet into my script. I keep getting an error about the variable being undefined. i have spent the last couple of hours trying to figure out what i am doing wrong so i wouldn't come back and ask for more help (i hate being a leech)

thanks for any further insight!!!!

scott

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 ,
Jun 25, 2018 Jun 25, 2018

Copy link to clipboard

Copied

Hi,

I have added the code into your script ( and cleaned up your script a wee bit, to make it easier to follow). hope this does what you want. let us know if you have any further questions.

#target indesign

// script wide variable

// we need a document for just about everything

// so declare it at the top

var curDoc = null

// as we need a document

// and we want to check fonts and images are correct,

// do that first

if (app.documents.length < 1)

{

    alert (" There are no active documents to work on")

    // as we need a document, stop the script

    exit();

}

else

{

    // we have a document

    // but lets check that it is suitable for us to use

    curDoc = app.activeDocument;

   

    // check for missing links

    // get the status of links in a string, there are other status' you might need to check

    // options are

    //LinkStatus.NORMAL

    //LinkStatus.LINK_OUT_OF_DATE

    //LinkStatus.LINK_MISSING

    //LinkStatus.LINK_EMBEDDED

    //LinkStatus.LINK_INACCESSIBLE

    var statusString = curDoc.links.everyItem().status.toString();

    if ( statusString.indexOf ("LINK_MISSING") !== -1)

    {

       alert (" Document has missing images");

        exit();

    }

   

    // check for missing fonts

    // get that status of the fonts and check, you need to pick the options from below to make sure you catch what you want.

    // options are

    // FontStatus.INSTALLED

    //FontStatus.NOT_AVAILABLE

    //FontStatus.FAUXED

    //FontStatus.SUBSTITUTED

    //FontStatus.UNKNOWN

    var fontStatus = curDoc.fonts.everyItem().status.toString();

    if  (( fontStatus.indexOf("NOT_AVAILABLE ") !== -1) || ( fontStatus.indexOf("SUBSTITUTED") !== -1 ))

    {

         alert ("Document appears to have missing fonts");

        exit();

    }

}

//=============== metatagging  ===============================

//-----document title and copyright---------

with (curDoc.metadataPreferences){

    copyrightInfoURL = "ABC company"

    copyrightNotice = "© 2018 ABC company";

    copyrightStatus = CopyrightStatus.yes;

    documentTitle = curDoc.name.split(".indd")[0];

    }

//---------------------add document name-------------------------------

with (curDoc.metadataPreferences){

        documentTitle = curDoc.name.split(".indd")[0];

        }

//-----------------------images to keywords--------------------------//

curDoc.metadataPreferences.keywords =

["ABC company"].concat(app.activeDocument.links.everyItem().name);

//-------------open file info dialog box---------------------

app.menuActions.itemByID(89092).invoke()

//=======================               packaging-                            ===================================-

// Package.jsx

//

// by Keith Gilbert

// gilbertconsulting.com

// blog.gilbertconsulting.com

//

// Revised 2018-01-15

//

// Check to see whether any InDesign documents are open.

// If no documents are open, display an error message.

///Prompt the user for the folder

var myTargetFolder = Folder.selectDialog("Select the folder in which to place the packaged files");

if (myTargetFolder != null)

{

    // Package the file

    curDoc.packageForPrint

    (

        to = myTargetFolder,

        copyingFonts = true,

        copyingLinkedGraphics = true,

        copyingProfiles = true,

        updatingGraphics = true,

        includingHiddenLayers = false,

        ignorePreflightErrors = true, // If this is set to false, and there are preflight errors, the script does nothing.

        creatingReport = false,

        includeIdml = false,

        includePdf = false,

        pdfStyle = "",

        useDocumentHyphenationExceptionsOnly = true, // Added to DOM in CC 2018

        versionComments = "",

        forceSave = true,

    )

}

else {

  exit();

}

//=================  make the PDFs  =====================================================

preset1 = app.pdfExportPresets.itemByName("press spreads and crops");  

preset2 = app.pdfExportPresets.itemByName("smallest size_spreads");      

if (!(preset1.isValid && preset2.isValid)){  

    alert("One of the presets does not exist. Please check spelling carefully.");  

    exit();  

}

mDocName = curDoc.name.substr (0, curDoc.name.lastIndexOf('.'));

mSourcePath = curDoc.fullName.parent.toString();

mRootPath =mSourcePath.substr (0, mSourcePath.lastIndexOf('/'));

mTargetPath=mRootPath.concat('/Final_Art/LowRes_PDF_Final/');

mNameWeb= mTargetPath.concat(mDocName,'_LOW.pdf');

mTargetPath=mRootPath.concat('/Final_Art/Print_PDF/');

mNamePrint = mTargetPath.concat(mDocName,'.pdf');  

if (!d.saved){  

    d.save;

}   

d.exportFile(ExportFormat.PDF_TYPE, new File(mNamePrint), false, preset1);  

d.exportFile(ExportFormat.PDF_TYPE, new File(mNameWeb), false, preset2);

Regards

Malcolm

[editied : to correct forntStatus if statement]

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
Explorer ,
Jun 25, 2018 Jun 25, 2018

Copy link to clipboard

Copied

wow....thank you!!!!

I worked on and off with this thru the day.

I fixed a reference in the "make PDF" portion that was still using my old reference to "d." so that is working.

the meta tagging is great

the package is working as expected

the check for missing images is working like a champ

but the check for missing fonts is giving me an issue. If no fonts are missing it works great but if there is a missing font it fails at the point where i am calling up the file info window line 81 above.

any more help or have i run the well dry?

scott

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 ,
Jun 26, 2018 Jun 26, 2018

Copy link to clipboard

Copied

Hi,

Are you able to share from a sharing site a document that shows the problem you describe so that I can investigate?

Regards

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
Explorer ,
Jun 26, 2018 Jun 26, 2018

Copy link to clipboard

Copied

a generic test file can be downloaded from the link below along with its associated files

I also included the .jsx file in case something happened when i copied (or attempted to fix) it

scott

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 ,
Jun 27, 2018 Jun 27, 2018

Copy link to clipboard

Copied

Hi Scott,

I was able to run the code without any problems with your document, I did notice an error in the font checking, so you probably want to make this change

// check for missing fonts

// get that status of the fonts and check, you need to pick the options from below to make sure you catch what you want.

// options are

// INSTALLED

//NOT_AVAILABLE

//FAUXED

//SUBSTITUTED

//UNKNOWN

var fontStatus = curDoc.fonts.everyItem().status.toString();

if  (( fontStatus.indexOf("NOT_AVAILABLE ") !== -1) || ( fontStatus.indexOf("SUBSTITUTED") !== -1 ))

{

     alert ("Document appears to have missing fonts");

    exit();

}

but other than that it worked as expected, missing image raised error and stopped, missing fonts raised error and stopped, if everything was ok it packaged teh document as per the instructions.

Regards

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
Explorer ,
Jun 27, 2018 Jun 27, 2018

Copy link to clipboard

Copied

I'm not sure what you changed ....but that made it work as planned!!!!

How do i mark the correct answer correctly....should i upload my "finished script" or mark the last one as correct?

...and is there anything more i can do than to say thank you?

scott

but...

now i am wondering if there is a way to make this script ignore hidden layers?

My documents tend to  use a lot of layers to customize a flyer or a brochure by having a generic base "template" and switching a series of logo layers on and off. i don't want it to return a "missing Image error" if it is on a hidden layer (which it currently does)

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 ,
Jun 29, 2018 Jun 29, 2018

Copy link to clipboard

Copied

Hi,

I have corrected my post with the full script, so if you mark that as correct, so that anyone else searching for this will be able to find the answer.

And of course we can add ignore layers but it does make is more complicated ( especially for the fonts check part).

For the link   it is just a case of check the visibility of the layer where the link is placed.

However for the fonts it is a bit harder, we could check as we currently do, and if there are no missing fonts in the document, then we are good to go, if there are missing fonts we would need to work out where the fonts where used and check if that layer was visible of each use of a missing font.

Regards

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
Explorer ,
Jun 29, 2018 Jun 29, 2018

Copy link to clipboard

Copied

i am humbled...

i feel like you are spoon-feeding me, giving me everything but the answer and i still spend so much time trying to get it to work but I fail!!! ( i did however get overset text to flag in the preflight and an alert to pop up let the operator know the script ran successfully)

how does the visible layer for linked objects work? I think i have tried every way that does not work!!!! can you show us one that does?

scott

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 ,
Jul 03, 2018 Jul 03, 2018

Copy link to clipboard

Copied

HI,

the links itself does not have a layer you have to get to the object that holds that link on the document, normally an image object, so you would need code something like

var allLinks = curDoc.links;

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

{

     if ( allLinks.parent.itemLayer.visible === true)

     {

          //run tests

     }

}

This should be able to be plugged in to the original code above and surround the part that checks the links.

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
Explorer ,
Jul 05, 2018 Jul 05, 2018

Copy link to clipboard

Copied

It still is finding links on non visible layers....what did i do wrong this time?

how does the second half know what is going on with var i?

    curDoc = app.activeDocument;

{

      var allLinks = curDoc.links;

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

  {

        if ( allLinks.parent.itemLayer.visible === true)

    {

                             // check for missing links  --------------------------------------------------------------------------------

                               // get the status of links in a string, there are other status’ you might need to check 

                                // options are 

                               //LinkStatus.NORMAL 

                                 //LinkStatus.LINK_OUT_OF_DATE 

                               //LinkStatus.LINK_MISSING 

                               //LinkStatus.LINK_EMBEDDED 

                             //LinkStatus.LINK_INACCESSIBLE 

           var statusString = curDoc.links.everyItem().status.toString(); 

           if ( statusString.indexOf (“LINK_MISSING”) !== -1) 

      { 

       alert (“ Document has missing images”); 

        exit(); 

      } 

    }

  }

}

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 ,
Jul 05, 2018 Jul 05, 2018

Copy link to clipboard

Copied

HI,

You can't use everyItem().status as that will get you the status of all the links so you need to change that loop to be something like.

As stated in previous replies, adding in a check for layer visibility makes it more complicated.

curDoc = app.activeDocument;

{

    var allLinks = curDoc.links;

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

    {

        if ( allLinks.parent.itemLayer.visible === true)

        {

            // check for missing links  --------------------------------------------------------------------------------

            // get the status of links in a string, there are other status’ you might need to check

            // options are

            //LinkStatus.NORMAL

            //LinkStatus.LINK_OUT_OF_DATE

            //LinkStatus.LINK_MISSING

            //LinkStatus.LINK_EMBEDDED

            //LinkStatus.LINK_INACCESSIBLE

            // Doing this makes sure we only check the links that are visible

            if ( allLinks.status == LinkStatus.LINK_MISSING)

            {

                alert (“ Document has missing images”);

                exit();

            }

        }

    }

}

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
Explorer ,
Jul 05, 2018 Jul 05, 2018

Copy link to clipboard

Copied

I knew that i was missing something connecting the variable i to the rest but am not say...

after a minor tweak from above (the alert has quote marks rather than inch marks) <---my fault it works like a champ.

I wish there was some way to get you a small token of appreciation, you have been so kind and generous with your knowledge

scott

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 ,
Jul 05, 2018 Jul 05, 2018

Copy link to clipboard

Copied

LATEST

HI,

No problem, happy to help out,

Regards

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