I currently have a (startup) script for my users that upon saving or beforeSave as event listener all links are added to the Copyright Notice field in Indesign. Upon each save this list is refreshed with the latest links.
I have another listener beforeExport that then takes this same information and adds to the already existing keywords placed in the InDesign document. The resulting PDF has the Existing keywords plus the links in the PDF Keywords Metadata Field. The keywords in the Indesign document are then reset to the original Keyword value, without the links. It is done this way so that the Keywords field does not build up with old image links etc
This works great whilst using InDesign on a users machine and exporting to PDF that way but as soon as I use Switch to take the Indesign file and produce a PDF through our preflight setup it does not work.
My feeling is the way Switch opens and uses InDesign does not actually use the Export which then triggers the script to perform in full.
I realise my code is not the best but have pasted below...
var myEventListener = app.addEventListener("beforeSave", GetListOfLinks, false);
var myEventListenerTwo = app.addEventListener("beforeExport", AddKeywords, false);
//Get Links list and place in Copyright Notice on Save
function GetListOfLinks(myEvent) {
var myDoc = app.activeDocument;
if (myDoc.links.length > 0) {
var myList = myDoc.links.everyItem().name.join("; ");
}
else {
var myList = "This document contains no links.";
}
var myMetaData = myDoc.metadataPreferences;
myMetaData.copyrightNotice = myList;
}
function AddKeywords(myEvent) {
var myDoc = app.activeDocument;
var ExistingKeywords = app.activeDocument.metadataPreferences.keywords;
if (myDoc.links.length > 0) {
var myList = [myDoc.links.everyItem().name.join(; )];
}
else {
var myList = "This document contains no links.";
}
var myMetaData = myDoc.metadataPreferences;
var AmendedKeywords = myList.concat(ExistingKeywords);
myMetaData.keywords = AmendedKeywords;
app.addEventListener("afterExport", ResetKeywords, false);
function ResetKeywords() {
app.activeDocument.metadataPreferences.keywords = ExistingKeywords;
}
}
InDesign Script for PDF Metadata
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
InDesign Script for PDF Metadata
I've not worked with EventListeners and Switch but I would try replacing "app.activeDocument" with "$doc"
-
- Newbie
- Posts: 2
- Joined: Tue Sep 20, 2011 2:20 pm
InDesign Script for PDF Metadata
Many thanks I tried this initially keeping with event listeners but in the end just ended with
var myDoc = $doc;
var ExistingKeywords = $doc.metadataPreferences.keywords;
if (myDoc.links.length > 0) {
var myList = [myDoc.links.everyItem().name.join(; )];
}
else {
var myList = "This document contains no links.";
}
var myMetaData = myDoc.metadataPreferences;
var AmendedKeywords = myList.concat(ExistingKeywords);
myMetaData.keywords = AmendedKeywords;
And then placed as Script in the Command of Indesign in Switch
var myDoc = $doc;
var ExistingKeywords = $doc.metadataPreferences.keywords;
if (myDoc.links.length > 0) {
var myList = [myDoc.links.everyItem().name.join(; )];
}
else {
var myList = "This document contains no links.";
}
var myMetaData = myDoc.metadataPreferences;
var AmendedKeywords = myList.concat(ExistingKeywords);
myMetaData.keywords = AmendedKeywords;
And then placed as Script in the Command of Indesign in Switch