Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Export pages to jpg with custom filenames

Guest
Aug 16, 2010 Aug 16, 2010

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.

TOPICS
Scripting
38.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2017 Sep 26, 2017

Another method here:

Re: How to export jpeg files with individual page names?

jchan_id2017  If the required page size info is in pixels, I have an alternative solution for you! It is not a simple one step export, however it only requires two steps.

This is “easily” achieved in Adobe Bridge using the Batch Rename tool…

In this example, the original INDD file was titled:

MyDoc.indd

It had two pages:

Page 1 = 800px wide x 600px tall

Page 2 = 1024px wide x 1889px tall

All pages were exported to JPEG using InDesign’s native File/Export command. This resulted in two files being output with the following names:

MyDoc.jpg

MyDoc2.jpg

Finally, Bridge’s Batch Rename tool was used to rename the files using their respective width and height metadata:

regex-rename.png

MyDoc.jpg           =     MyDoc_800w_600h.jpg

MyDoc2.jpg         =     MyDoc_1024w_1889h.jpg

P.S. The Batch Rename can be saved as a preset for future use and the preset can also be shared with other Bridge users in your team.

EDIT: Here is a slightly simplified version of the Batch Rename tool setup, both should return the same result.

regex-rename-v2.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 20, 2018 Dec 20, 2018

Hi Sidrunitops

yay! I feel like I'm getting somewhere

This is the solution I'm looking for. I have the code in ExtendScript Tool and I have the data in a .csv file (that I used to data merge) in my column 1 is the name I would like the file to be called .jpg.

Where in code (posted above) do I slot in some more code that would use my .csv file to custom name each page?

PS: I'm using InDesign CC 2018

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 20, 2018 Dec 20, 2018

MsSandyO

When it comes to coding questions, the best place for this question is in the InDesign Scripting forum here:

InDesign Scripting

That's where all the scripters hang out.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 09, 2011 Oct 09, 2011

I was able to get this to export in CS4 using the script someone had posted for me. If I remember right, I had to create a new section for each page, and it would read that section marker's label and use it for the jpg's filename. Was VERY handy if you have a portfolio that you want to export each page as jpg with a custom name.

The script had within it a setting for the jpg quality a well, which you would have to change manually within the script (which wasn't terribly difficult).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 10, 2011 Oct 10, 2011

Was it the script in this discussion or another script you used?

Would you be able to post a sample please?

Thank you – regards - Janice

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 10, 2011 Oct 10, 2011

Ok, so I realized I used this in CS5.

Attaching the script file here, and if that doesnt come through, see script included (which I believe I pulled from post #5 above).

USE THIS

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 10, 2011 Oct 10, 2011

Sorry nothing attached.

I’m also using CS5.

what is it I need to change in the script in post #5 above to tell it to export using the section names?

If I can get this to work, it will be a life saver!!

Thank you - Janice

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 10, 2011 Oct 10, 2011

See #8-10 for modifying posted script to work in CS5. It's coded to pull from the section name, so nothing you should have to do. (sorry, it was over a year ago I did this so everything's a little fuzzy)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 10, 2011 Oct 10, 2011

I’ve can run the script, I just can’t get it to export the JPGs with the Section names.

I only get the automates page numbering.

I think I’ll have to give up.

thank you for your help.

Janice

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 10, 2011 Oct 10, 2011

cdnyc:

See #8-10 for modifying posted script to work in CS5. It's coded to pull from the section name, so nothing you should have to do.

That's not what I see. It appears to simply blank out the section name:

if (myDoc.pages.item(myCounter).appliedSection.name != "") {
    myDoc.pages.item(myCounter).appliedSection.name = "";
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 05, 2011 Dec 05, 2011

John, you are right about that it will blank out the section name. After I have applied new section name this script will in some way reset section name back to "zero".

I would be really greatfull if I could get this script to work with applying the section name, do you have any suggestions how to do this?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 05, 2011 Dec 05, 2011

And:

I don't really understand why Kasyan explicitly removes the section name, but you should be able to remove (or comment out) those 3 lines and have the script work. I also don't know what you mean by "applying the section name," though. Applying it to what?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 06, 2011 Dec 06, 2011

Sorry for my bad english John, I removed the three lines and now it works the way I wanted to. It will now export .jpg files with the specific name I put in the section prefix. Thank you very much for your help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 06, 2011 Dec 06, 2011

You're welcome, AndSchWall.

As for text variables, _acadamie, well, I think that's doable but more annoying. Try figuring it out yourself .

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 25, 2012 Sep 25, 2012

Sorry to open up this post again, but I really can't get this to work with CS5.5
I also would like to use this script so that I can export each page as a JPG and that it will use the Section prefix as the name for that JPG.

I have the following code in Toolscript:

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.exportResolution = 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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 12, 2013 Feb 12, 2013

Hey Sirbaxx,

I'm currently working on a project that needs the Section Prefix and Page Number in the filename. It worked for me by replacing this line:

          var myPageName = myDoc.pages.item(myCounter).name;

with this:

          var myPageName = myDoc.pages.item(myCounter).appliedSection.name + myDoc.pages.item(myCounter).name;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 15, 2013 Feb 15, 2013

Thanks a lot Futabos, this was exactly what I'm looking for!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 28, 2013 Jun 28, 2013

Futabos,thanks for your code. this works well for me. now this code will export the section prefix and page number as: [TEXT]_[SECTION][PAGE NUMBER].jpg

However,i want to modify this to  [TEXT]_[SECTION]_[PAGE NUMBER].jpg .i had some play arround the code, but i know nearly nothing about computer lanague.

please help.

 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++) {

          //var myPageName = myDoc.pages.item(myCounter).appliedSection.name
          var myPageName = myDoc.pages.item(myCounter).appliedSection.name + myDoc.pages.item(myCounter).name;
          app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.medium; // low medium high maximum
          app.jpegExportPreferences.exportResolution = 300;
          app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;
          app.jpegExportPreferences.pageString = myPageName;
          var myFilePath = myDoc.filePath + "/" + 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;

} 
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2014 Oct 09, 2014

hey

var myPageName = myDoc.pages.item(myCounter).appliedSection.name + myDoc.pages.item(myCounter).name; 

is it possible to replace the section name with the content of the SectionMarker? i cant find out what´s the right code to get the content/string from the sections marker.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2014 Oct 09, 2014

hey

var myPageName = myDoc.pages.item(myCounter).appliedSection.name + myDoc.pages.item(myCounter).name; 

is it possible to replace the section name with the content of the SectionMarker? i cant find out what´s the right code to get the content/string from the sections marker.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 28, 2017 Jun 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.Bildschirmfoto 2017-06-28 um 13.56.34.png

Bildschirmfoto 2017-06-28 um 13.58.35.png

Bildschirmfoto 2017-06-28 um 13.57.38.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 26, 2017 Sep 26, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2017 Sep 26, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 09, 2019 Dec 09, 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?
}
}
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines