Copy link to clipboard
Copied
Trying to find out if there is a way I can export the pages of an InDesign document so that each exported jpg could have a unique name I am able to specify before exporting, instead of going in afterwards and renaming each one.
Copy link to clipboard
Copied
Not really, the closest you will be able to get is Scott Zanelli's free Page Exporter Utility script, I'd google Indesign Secrets Page Exporter Utility and you should find it, sorry I can't give you the link at the moment. It comes with a manual explaining how it works.
Copy link to clipboard
Copied
I doubt I'll get exactly what I want. I'll take a look however. Thanks
Copy link to clipboard
Copied
You could also try something like Name Mangler http://manytricks.com/namemangler/ to batch rename. It'll save you some time. I often find this easiest.
Copy link to clipboard
Copied
Depending on how handy you are with Javascript, it may be faster to write a custom jpeg-exporter script.
(I'm a painfully slow scripter. When I'm on the Mac, I use NameMangler.)
Copy link to clipboard
Copied
Here I slapped up a script:
if (app.documents.length != 0) {
var myDoc = app.activeDocument;
var myBaseName = prompt ("Enter basic name", GetFileNameOnly(myDoc.name), "Basic name");
if (myBaseName != null) MakeJPEGfile();
}
else{
alert("Please open a document and try again.");
}
function MakeJPEGfile() {
for(var myCounter = 0; myCounter < myDoc.pages.length; myCounter++) {
if (myDoc.pages.item(myCounter).appliedSection.name != "") {
myDoc.pages.item(myCounter).appliedSection.name = "";
}
var myPageName = myDoc.pages.item(myCounter).name;
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.medium; // low medium high maximum
app.jpegExportPreferences.resolution = 72;
app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;
app.jpegExportPreferences.pageString = myPageName;
var myFilePath = "~/Desktop/" + myBaseName + "_" + myPageName + ".jpg";
var myFile = new File(myFilePath);
myDoc.exportFile(ExportFormat.jpg, myFile, false);
}
}
function GetFileNameOnly(myFileName) {
var myString = "";
var myResult = myFileName.lastIndexOf(".");
if (myResult == -1) {
myString = myFileName;
}
else {
myString = myFileName.substr(0, myResult);
}
return myString;
}
Warning! The script removes section prefixes.
Kasyan
Copy link to clipboard
Copied
Wow, someone's my new best friend
So now I'll reveal my programming prowess... What do I need to do to implement this? I come from a design background, so this is a little foreign to me.
Copy link to clipboard
Copied
Kasyan
Copy link to clipboard
Copied
I tried this with the InDesign CS5, but got error on this line:
app.jpegExportPreferences.resolution = 72;
How should I fix the line in order to get the script work?
Thanks in advance!
Copy link to clipboard
Copied
I can't test it myself — don't have CS5 at hand. Try to change this line to
app.jpegExportPreferences.exportResolution = 72;
Kasyan
Copy link to clipboard
Copied
That worked! Thnak you!
Sent from my iPhone
Copy link to clipboard
Copied
That worked! Thank you!
Copy link to clipboard
Copied
First of all, thank you so much for this script. I know next to nothing about scripting, but I was able to modify this to rename our files for ad proofs (we got tired of clients 'cracking' our PDFs for other vendors). I was wondering, is there a way to modify the script so that it saves the exported file into the same folder as the file you're exporting from? We're working from a server, so this would save us a drag & drop each time.
Thanks again.
Copy link to clipboard
Copied
TaraRebeka: Yes, just replace this line:
var myFilePath = "~/Desktop/" + myBaseName + "_" + myPageName + ".jpg";
with this:
var myFilePath = myDoc.filePath + "/" + myBaseName + "_" + myPageName + ".jpg";
Copy link to clipboard
Copied
Sir, you have made me a hero at work. Thank you!
Copy link to clipboard
Copied
Hi John, Any ideas of what line I'd have to add to export with bleed settings? Thanks for your time
Copy link to clipboard
Copied
Hi Kasyan, this script has worked amazingly, THANK YOU so much! I've also been trying to adapt it for png process (not sure if it is even possible), but it gets stuck on line 16. I know png has slightly different options at the bottom of the export options, such as 'Transparent Background' which I do want ticked. What I currently have is below, what am I doing wrong? Thanks for all your help!
Mari
________________________________
if (app.documents.length != 0){
var myDoc = app.activeDocument;
MakePNGfile();
} else {
alert("Please open a document and try again.");
}
function myPS() {
try {
return myDoc.selection[0].appliedParagraphStyle;
} catch (e) {
alert("Place cursor to text with paragraph style for filenames");
exit();
}
}
function MakePNGfile() {
app.pngExportPreferences.pngQuality = PNGOptionsQuality.maximum;
app.pngExportPreferences.exportResolution = 72;
app.pngExportPreferences.pngExportRange = ExportRangeOrAllPages.exportRange;
app.findGrepPreferences = null;
app.findGrepPreferences.appliedParagraphStyle = myPS();
var f = myDoc.findGrep();
for (var myCounter = 0; myCounter < f.length; myCounter++) {
try {
var curPage = f[myCounter].parentTextFrames[0].parentPage;
if (curPage.appliedSection.name != "") {
curPage.appliedSection.name = "";
}
var objName = f[myCounter].contents.replace(/ /g,"_").toLowerCase();
app.pngExportPreferences.pageString = curPage.name;
var myFilePath = myDoc.filePath + "/" + objName + ".png"; //export to a folder of the current document
var myFile = new File(myFilePath);
myDoc.exportFile(ExportFormat.png, myFile, false);
} catch(e) {
//pasteboard?
}
}
}
Copy link to clipboard
Copied
Here all your answers can be found to set png preference:
Adobe InDesign CS6 (8.0) Object Model JS: PNGExportPreference
app.pngExportPreferences.pngQuality = PNGQualityEnum.MAXIMUM;
app.pngExportPreferences.transparentBackground = true;
I didnt test this, but you should get along
Copy link to clipboard
Copied
Thanks DBLjan, I don't know what I'd do without you guys! Well, I do know – I'd do it the hard way (manually, individually) LOL
Have a great weekend! M
Copy link to clipboard
Copied
Here's my version of the script:
if (app.documents.length != 0){
var myDoc = app.activeDocument;
MakePNGfile();
} else {
alert("Please open a document and try again.");
}
function myPS() {
try {
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
return myDoc.selection[0].appliedParagraphStyle;
}
else if (app.selection.length == 0) {
alert("Nothing is selected.");
exit();
}
else {
alert("Some text should be selected, or the cursor should be inserted into the text.");
exit();
}
} catch (e) {
alert("ERROR: " + e.message + ", line: " + e.line);
}
}
function MakePNGfile() {
app.pngExportPreferences.pngQuality = PNGQualityEnum.MAXIMUM;
app.pngExportPreferences.transparentBackground = true;
app.pngExportPreferences.exportResolution = 72;
app.pngExportPreferences.pngExportRange = PNGExportRangeEnum.EXPORT_RANGE;
app.findGrepPreferences = null;
app.findGrepPreferences.appliedParagraphStyle = myPS();
var f = myDoc.findGrep();
for (var myCounter = 0; myCounter < f.length; myCounter++) {
try {
var curPage = f[myCounter].parentTextFrames[0].parentPage;
if (curPage.appliedSection.name != "") {
curPage.appliedSection.name = "";
}
var objName = f[myCounter].contents.replace(/\s+/g,"_").toLowerCase();
app.pngExportPreferences.pageString = curPage.name;
var myFilePath = myDoc.filePath + "/" + objName + ".png"; //export to a folder of the current document
var myFile = new File(myFilePath);
myDoc.exportFile(ExportFormat.PNG_FORMAT, myFile, false);
} catch(e) {
alert("ERROR: " + e.message + ", line: " + e.line);
}
}
}
Note: unlike AppleScript, JavaScript is case-sensitive.
Also, make sure to look into the scripting reference for correct terms.
For example, you wrote:
myDoc.exportFile(ExportFormat.png, myFile, false);
instead of
myDoc.exportFile(ExportFormat.PNG_FORMAT, myFile, false);
I recommend you to use the "copy and paste" approach to avoid typos.
You can use the 'baseline' property to check if text is selected (line 10)
If an unexpected error occurs, add an alert which displays the error message and the line where it occurs (lines 22 and 50), or $.writeln to see them only written into console while debugging in ESTK.
Use \s+ to replace one or more any spaces with underscore in file names: can be 2+ spaces in a row, tab, etc.
Hope it helps!
— Kas
Copy link to clipboard
Copied
Wow, thanks heaps! Will try it with my old InDesign CS at home (have CC 2019 at work).
Unfortunately I know nothing about coding/scripting, I'm just using trial & error methods and trying to apply logical thinking But as you can see there are limits to it so I truly appreciate the help – could not have solved this myself! I will report back. Happy weekend to you, it's 8pm Fri here in Auckland! M
Copy link to clipboard
Copied
Hiya, I hope you won't laugh at my ancient ID version (CS 5.5, but it works great). I tried the copy-pasted script with it but now I get a different error:
Here's what the script panel looks like:
I assume this is JavaScript, not Apple Script (that's how much I know...LOL).
M
Copy link to clipboard
Copied
I don't have CS5.5 so can't check it, but as far as I understand, CS5.5 has no app.pngExportPreferences property because it has no PNG export feature which appeared in the next version: CS6.
You can add the following lines at top to check Indy's version:
var appVersion = Number(String(app.version).split(".")[0]);
if (appVersion < 8) {
alert("This script requires CS6 or above.");
}
Forgot to mention: in the future, use syntax highlighting (advanced editor) to post your code.
Copy link to clipboard
Copied
You are so right! Just checked the export and there is no png option there. Can't wait to get back to work on Monday (thought I'd never say that, haha!). You're a gem, Kasyan!
Copy link to clipboard
Copied
I found that out too in here http://jongware.mit.edu/iccs5.5js_html/iccs5.5js/ because i did not found it
Maybe that could be a solution:
It seems that your company has some kind of abo-plan on the creative suite. After some discussions, I layed out to my boss that we would only benefit from letting the users make use of the CS at home (beiing able to do doing tutorials, get skilled, get better). Were running a team license, which our IT adminsitartes. When we get new coworkers, their private AdobeID is added to the teamcloud, and can be deleted also. Thus making our IT control, that leaving coworkers wont block the license or do something bad with it.
That enables me to use the full CS app-set at home, while just the Adobe Cloud is forbidden.
We have some coworkers who preserve an old private version of InDesign (which I assume isnt always legal purchased), which get incompatible to our company workflow. So I pushed that project