With the script I'm writing, I want it to open an InDesign document (.indd), remove the items from the pasteboard and re-link any missing images, then after that executes, the InDesign configurator should be able to pass the document and export a PDF. I've got the script working so that it removes the pasteboard items and I could even technically export a PDF from within the script but the person who designed this flow (I'm just doing the scripting part for this) wants the Configurator to pass or fail the InDesign file. The problem is I get the following error every time:
Code: Select all
Script returned error: ERROR: ImagesFail: Unavailable images were found in the document
Here is the script I have (below) and I would greatly appreciate any insight on how to improve this and/or what I could do differently to get the result I want.
Code: Select all
// Open the document in InDesign
var switchFile = File($infile);
var curDoc = app.open( switchFile );
// Functions to remove the pasteboard items that aren't
// needed any longer.
function removePasteboardItems(/*?Document*/doc)
//--------------------------------------
{
if( !doc ) return;
var items = doc.pageItems.everyItem().getElements(),
t = null;
while( t=items.pop() ) t.parentPage || removeItem(t);
t = items = null;
}
function removeItem(/*PageItem*/item)
//--------------------------------------
{
try {
item.locked = false;
item.remove();
}
catch(_){}
}
// Running the function and pushing through the document via app
removePasteboardItems(app.documents.length && app.activeDocument);
// Save the InDesign file to see which location the document is looking for links in
//app.activeDocument.save(File("/c/tmp/New.indd"));
// Function to replace/restore links in the document that are missing or not available
// Does not seem to be working...
function checkDoc(doc) {
var fts = doc.fonts;
var lks = doc.links;
var missingFonts = [];
var missingLinks = [];
var n = fts.length;
var msg = "";
while (n--) {
if ( /SUBSTITUTED|NOT_AVAILABLE/.test ( fts[n].properties.status.toString() ) ){
missingFonts [ missingFonts.length ] = fts[n].name.replace ( /\t+/g, " ");
}
}
n = lks.length;
while (n--) {
if ( /LINK_MISSING|LINK_INACCESSIBLE/.test ( lks[n].properties.status.toString() ) ) {
missingLinks[ missingLinks.length ] = lks[n].name;
}
}
if ( missingFonts.length ) msg+= missingFonts.length+" missing fonts ["+missingFonts.join()+"]. ";
if ( missingLinks.length ) msg+= missingLinks.length+" missing links ["+missingLinks.join()+"]. ";
return ( missingFonts.length || missingLinks.length )? msg : "";
}
// Checking the active $doc
var c = checkDoc($doc);
c!="" && $error = c;
//Close the document and save changes
curDoc.close(SaveOptions.NO)
Code: Select all
Script returned error: ERROR: User canceled this action.
Is there any way to process the document as mentioned above and have it pass the Configurator tests for "Fail jobs with unavailable fonts" and "Fail jobs with unavailable images"? Or, if I use the script above and export a PDF, would that result in a PDF that contains all of the information in the trim/bleed area?