Dave Saunders
02-03-2005, 05:10 PM
I'm acting/directing a play at the church and I needed to print out some personalized calendars, so I banged out this quick script to personalize the calendar and print out a copy for each person:
myDoc = app.activeDocument;
myStyle = myDoc.characterStyles.item("Person");
myPreset = app.printerPresets.item("LWProWide");
myFolk = ["Dave","Denise","Jeff","Shannon", "Jerry", "Eric", "Mel"];
for (i=0; myFolk.length>i; i++) {
app.findPreferences = null;
app.changePreferences = null;
myDoc.search("",false,false,myFolk[i],{appliedCharacterStyle:myStyle});
myDoc.print(false,myPreset);
}
I'm posting this partly to test the code tags (they work!). But the script is fairly easy to follow, I think. First, I set myDoc to reference the active document. Then, I setup a reference to the character style named "Person" -- if you try this script on a document that doesn't have such a style, it will give an error at this point.
Similarly, I set up a reference to the printer preset I'm going to use with the print command. Again, if you don't have a preset with this name, this script will die here.
Obviously, you can change the names in the script to match your character style and print preset.
myFolk is an array of the names of the people for whom I'm creating the document.
Then the loop uses Find/Change to replace each instance of text in the Person character style to be the each name in turn, printing a copy before moving on to the next person. In my case, I had a three page document with the name on each page.
This is a JavaScript. To use it, copy and paste it to a plain text file with a name like PersonalizedPrint.js in the Scripts folder of the Presets folder of your InDesign CS application folder.
Dave
myDoc = app.activeDocument;
myStyle = myDoc.characterStyles.item("Person");
myPreset = app.printerPresets.item("LWProWide");
myFolk = ["Dave","Denise","Jeff","Shannon", "Jerry", "Eric", "Mel"];
for (i=0; myFolk.length>i; i++) {
app.findPreferences = null;
app.changePreferences = null;
myDoc.search("",false,false,myFolk[i],{appliedCharacterStyle:myStyle});
myDoc.print(false,myPreset);
}
I'm posting this partly to test the code tags (they work!). But the script is fairly easy to follow, I think. First, I set myDoc to reference the active document. Then, I setup a reference to the character style named "Person" -- if you try this script on a document that doesn't have such a style, it will give an error at this point.
Similarly, I set up a reference to the printer preset I'm going to use with the print command. Again, if you don't have a preset with this name, this script will die here.
Obviously, you can change the names in the script to match your character style and print preset.
myFolk is an array of the names of the people for whom I'm creating the document.
Then the loop uses Find/Change to replace each instance of text in the Person character style to be the each name in turn, printing a copy before moving on to the next person. In my case, I had a three page document with the name on each page.
This is a JavaScript. To use it, copy and paste it to a plain text file with a name like PersonalizedPrint.js in the Scripts folder of the Presets folder of your InDesign CS application folder.
Dave