Skip to main content
August 16, 2010
Question

Export pages to jpg with custom filenames

  • August 16, 2010
  • 6 replies
  • 38427 views

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.

This topic has been closed for replies.

6 replies

Participant
December 9, 2019

So I got this Script working from the forum posts here, it exports the doc as JPGs with a name equal to the currently selected paragraph style (if style is present on each page).

What I wish it could do is the following

- Be able to find paragraph styles within the slug area (currently they must be present on the canvas to work)
- I would like a duplicate version of this script that just exports the current page instead of the whole doc
- Popup an alert when the export is finished

Could anyone give me some hints how to add these bits of functionality? Thanks! 

 

if (app.documents.length != 0){
var myDoc = app.activeDocument;
MakeJPEGfile();
} 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 MakeJPEGfile() {

app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.maximum;
app.jpegExportPreferences.exportResolution = 300;
app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;
app.jpegExportPreferences.useDocumentBleeds = true;

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.jpegExportPreferences.pageString = curPage.name;
var myFilePath = myDoc.filePath + "/" + objName + ".jpg"; //export to a folder of the current document
var myFile = new File(myFilePath);
myDoc.exportFile(ExportFormat.jpg, myFile, false);
} catch(e) {
//pasteboard?
}
}
}

 

Participant
September 27, 2017

Thanks @Stephen_A_Marsh. I will have to give this a try when I get back to work tomorrow. I had no idea the batch rename feature in Bridge was so robust.

Stephen Marsh
Community Expert
Community Expert
September 27, 2017

Thanks @Stephen_A_Marsh. I will have to give this a try when I get back to work tomorrow. I had no idea the batch rename feature in Bridge was so robust.

My pleasure, yes it is robust and having the ability to use regular expressions as well as file properties and metadata makes it very useful indeed.

P.S. Although my screenshots did not show it, I recommend checking the option for “Preserve current filename in XMP metadata” whenever batch renaming (if you are not working with copies). That way you can revert if there is a mistake or unexpected result that is not shown using the preview.

Legend
June 28, 2017

I have a quick and dirty solution for you:

var myDoc = app.activeDocument;

app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;

app.jpegExportPreferences.exportingSpread = false;

app.jpegExportPreferences.antiAlias = true;

app.jpegExportPreferences.exportResolution = 72;

for (var i = 0; i < myDoc.bookmarks.length; i++) {

app.jpegExportPreferences.pageString = myDoc.bookmarks.destination.destinationPage.name;

var myPath = "~/Desktop/" + myDoc.name.substring(0,(myDoc.name.search(".indd")))  + "_" + myDoc.bookmarks.name + ".jpg";

var myFile = new File(myPath); 

myDoc.exportFile(ExportFormat.jpg, myFile, false);

};

After modifiying the details (DPI? AA? Spreads?) in my script, you advance like this:
Doubleclick a page in your page window, to select the page, not a/the content.
Open up the Bookmarks-window.

Now create a page-bookmark with your disired output name. Note that there can be many bookmarks with different names pointing to a single page.

October 9, 2011

RE Export pages to jpg with custom filenames

HELP PLEASE!!

If I have 10 pages in my InDesign document and want to export all 10 pages at once as individualy named JPGs, what do I need to do?

Do I have to use separators in the box that pops up when I execute the script, or amend the script in some way

.

Help would be greatly appreciated as it would save me hours of renaming time when my boss keeps changing his mind!!!

Regards - Janice

BobLevine
Community Expert
Community Expert
October 9, 2011

For renaming files, use Bridge.

Bob

October 9, 2011

That won’t work for me as each page (over 200 of them) have unique names but always get exported with these unique names.

eg bclol2pk.jpg bogofp.jpg and it goes on.

Bridge will defiantly come in handy when I have to add the prefix for each new batch.

The forum: http://forums.adobe.com/message/3063985 seemed to suggest I could run the script that could export each page as a unique JPG name.

Thank you!

Janice

Kasyan Servetsky
Legend
August 18, 2010

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

August 18, 2010

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.

Kasyan Servetsky
Legend
August 18, 2010
  1. Copy the script from the forum (make sure to copy the whole script , otherwise it won't work).
  2. Run Adobe ExtendToolkit (or Notepad)
  3. Create new document and paste
  4. Save it in Scripts Panel folder (either User or Application) -- you can quickly get there by Opt/Alt clicking on it in Scripts panel
  5. To run the script just double click its name in Scripts panel

Kasyan

Stix_Hart
Inspiring
August 16, 2010

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.

August 16, 2010

I doubt I'll get exactly what I want. I'll take a look however. Thanks

FivePicaPica
Inspiring
August 16, 2010

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.