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

Export pages to jpg with custom filenames

Guest
Aug 16, 2010 Aug 16, 2010

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.

TOPICS
Scripting

Views

33.7K

Translate

Translate

Report

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
Guru ,
Aug 16, 2010 Aug 16, 2010

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.

Votes

Translate

Translate

Report

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
Aug 16, 2010 Aug 16, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Aug 16, 2010 Aug 16, 2010

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.

Votes

Translate

Translate

Report

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 ,
Aug 16, 2010 Aug 16, 2010

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.)

Votes

Translate

Translate

Report

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
Guru ,
Aug 18, 2010 Aug 18, 2010

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

Votes

Translate

Translate

Report

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
Aug 18, 2010 Aug 18, 2010

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.

Votes

Translate

Translate

Report

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
Guru ,
Aug 18, 2010 Aug 18, 2010

Copy link to clipboard

Copied

  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

Votes

Translate

Translate

Report

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
Jan 01, 2011 Jan 01, 2011

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!

Votes

Translate

Translate

Report

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
Guru ,
Jan 01, 2011 Jan 01, 2011

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

Votes

Translate

Translate

Report

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
Jan 01, 2011 Jan 01, 2011

Copy link to clipboard

Copied

That worked! Thnak you!

Sent from my iPhone

Votes

Translate

Translate

Report

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
Jan 01, 2011 Jan 01, 2011

Copy link to clipboard

Copied

That worked! Thank you!

Votes

Translate

Translate

Report

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
Explorer ,
Jan 19, 2012 Jan 19, 2012

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.

Votes

Translate

Translate

Report

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 ,
Jan 19, 2012 Jan 19, 2012

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";

Votes

Translate

Translate

Report

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
Explorer ,
Jan 20, 2012 Jan 20, 2012

Copy link to clipboard

Copied

Sir, you have made me a hero at work. Thank you!

Votes

Translate

Translate

Report

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
Explorer ,
Oct 03, 2023 Oct 03, 2023

Copy link to clipboard

Copied

LATEST

Hi John, Any ideas of what line I'd have to add to export with bleed settings? Thanks for your time

Votes

Translate

Translate

Report

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
Explorer ,
Jul 18, 2019 Jul 18, 2019

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

Screen Shot 2019-07-19 at 2.51.18 PM.png

________________________________

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?

}

}

}

Votes

Translate

Translate

Report

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 ,
Jul 18, 2019 Jul 18, 2019

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

Votes

Translate

Translate

Report

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
Explorer ,
Jul 19, 2019 Jul 19, 2019

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

Votes

Translate

Translate

Report

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
Guru ,
Jul 19, 2019 Jul 19, 2019

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

Votes

Translate

Translate

Report

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
Explorer ,
Jul 19, 2019 Jul 19, 2019

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

Votes

Translate

Translate

Report

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
Explorer ,
Jul 19, 2019 Jul 19, 2019

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:

Screen Shot 2019-07-19 at 20.26.22.png

Here's what the script panel looks like:

Screen Shot 2019-07-19 at 20.31.50.png

I assume this is JavaScript, not Apple Script (that's how much I know...LOL).

M

Votes

Translate

Translate

Report

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
Guru ,
Jul 19, 2019 Jul 19, 2019

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.

2019-07-19_10-34-36.png

Votes

Translate

Translate

Report

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
Explorer ,
Jul 19, 2019 Jul 19, 2019

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!

Votes

Translate

Translate

Report

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 ,
Jul 19, 2019 Jul 19, 2019

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

Votes

Translate

Translate

Report

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