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

Script to export individual Pages with specific names to jpeg

Community Beginner ,
Oct 11, 2021 Oct 11, 2021

Hello, I am in need of a script to help export pages of different web sizes to jpeg with the File name + websize name. 

Examples: Job123_Email_600x300.Jpeg  | Job123_web_1200x700.Jpeg

I have each page within indesign built according to the size of the web. I couldnt for the life of me figure out how to somehow specify within a script to name page 1 = email_600x300 and page 2 = web 1200x700 and so on. 

 

I don't have any knowlege with scripting, I did however created a script 2 years ago from just trial and error and messing with example scripts to export pdf or jpeg with multiple variations ( layers on or off) 

// Proof pdf export version, smallest file size.
var myDocument = app.documents.item(0);
var myDoc = app.activeDocument;
var layers = myDocument.layers;
var slots, tables, hosted, nonHosted, hotel, promos, translation, i, myFileName;
// Export location
var myFolder = Folder.desktop;
// PDF Preset specification
// PDF PRESET SELECTIONS
var myPresets = app.pdfExportPresets.everyItem().name;
myPresets.unshift("- Select Preset -");
var myWin = new Window('dialog', 'PDF Export Presets');
myWin.orientation = 'row';
with(myWin){
myWin.sText = add('statictext', undefined, 'Select PDF Export preset:');
myWin.myPDFExport = add('dropdownlist',undefined,undefined,{items:myPresets});
myWin.myPDFExport.selection = 0;
myWin.btnOK = add('button', undefined, 'OK');
};
myWin.center();
var myWindow = myWin.show();
 
if(myWindow == true && myWin.myPDFExport.selection.index != 0){
var myPreset = app.pdfExportPresets.item(String(myWin.myPDFExport.selection));
}else{
alert("No PDF Preset selected");
}
for(var myCounter = 0; myCounter < 8; myCounter ++){
switch(myCounter){
case 0:
// Slots Version
// Hosted
fileName = "16853_DBM_Mailer_07_19_Back_Slots_Hosted";
slots = "Slots";
hosted = "Hosted Vault W-F";
hotel = "BS Hosted";
promos = "off";
translation = "off";
break;
case 1:
// Non_Hosted
fileName = "16853_DBM_Mailer_07_19_Back_Slots_Non_Hosted";
slots = "Slots";
hosted = "Hosted Vault W-F";
nonHosted;
hotel = "BS Non Hosted";
promos = "off";
translation = "off";
break;
case 2:
// Slots Translated Version
fileName = "16853_DBM_Mailer_07_19_Back_Slots_Translated";
slots = "Slots";
hosted = "Hosted Vault W-F";
hotel = "BS Hosted";
promos= "off"
translation = "F&B Translated";
break;
case 3:
// Tables Version
// Hosted
fileName = "16853_DBM_Mailer_07_19_Back_Tables_Hosted";
slots = "off";
tables = "Tables";
hosted = "Hosted Vault W-F";
hotel = "BS Hosted";
promos = "off";
translation = "off";
break;
case 4:
// Non_Hosted
fileName = "16853_DBM_Mailer_07_19_Back_Tables_Non_Hosted";
slots = "off";
tables = "Tables";
nonHosted;
hosted = "Hosted Vault W-F";
hotel = "BS Non Hosted";
promos = "off";
translation = "off"
break;
case 5:
// Tables Translated Version
fileName = "16853_DBM_Mailer_07_19_Back_Tables_Translated";
slots = "off";
tables = "Tables";
hosted = "Hosted Vault W-F";
hotel = "BS Hosted";
promos = "off"
translation = "F&B Translated";
break;
}
for(i = 0; i < myDocument.layers.length; i ++){
if((layers.item(i).name == slots )|| (layers.item(i).name == tables )|| (layers.item(i).name == hosted )|| (layers.item(i).name == nonHosted )||
(layers.item(i).name == hotel )|| (layers.item(i).name == promos )|| (layers.item(i).name == "L8P Drawing Tues")|| (layers.item(i).name == "ENT Nightlife")||
(layers.item(i).name == "Car Promo")|| (layers.item(i).name == "F&B")|| (layers.item(i).name == "Retail")|| (layers.item(i).name == "Battle Cards")||
(layers.item(i).name == "Club Serrano Benefits")|| (layers.item(i).name == "Overlays")|| (layers.item(i).name == translation )|| (layers.item(i).name == "Cash Sundays")){
layers.item(i).visible = true;
layers.item(i).printable = true;
}
else{
layers.item(i).visible = false;
}
}
myFileName = myFolder + "/" + fileName + ".pdf";
myDocument.exportFile(ExportFormat.pdfType, File(myFileName), false, myPreset);
}
 
That worked great for that specific project that happens on a month bases which required upto 72 variations when exporting for proof. But this was long time ago I totally forgot how it all works and plus that is for layers and each indesign file has 1 page only.

If anyone can help with a simple script I can go in and customize that would be much appreciated. 
 
The websizes won't change, so the scripts I found online where it gives you a prompt to manually enter the name isnt going to work. I prefer to set the naming within the script as it does not need to change. 

Thanks!
TOPICS
Scripting
2.2K
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

correct answers 1 Correct answer

Community Beginner , Oct 19, 2021 Oct 19, 2021

Sorry for the late reply, thanks Mike. However I figured it out and here is the script that I ended up with. It works quite well and it can export both PNG and JPG at the same time. 

var myDoc = app.activeDocument;


for(var p = 0; p < app.documents[0].pages.length; p++) {  
  var frames = app.documents[0].pages[p].textFrames;
  var jpg_name = null; 
  

  for(var i = 0; i < frames.length; i++) { 
   try { 
       if(frames[i].paragraphs[0].appliedParagraphStyle.name == 'title') {  
         jpg_
...
Translate
Community Expert ,
Oct 13, 2021 Oct 13, 2021

I don't know how to do it with scripting.

But you can do this with Bookmarks and PDF - then save to JPEG.

 

https://creativepro.com/data-merging-individual-records-separate-pdfs/

 

 

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
Advisor ,
Oct 14, 2021 Oct 14, 2021

Hello @defaults0afwy5szys8,

Give the below script a try.

You'll need to set the jpg export preferences to your specific needs and build out the the rest of the sizes in the switch statement as I only did it with the two examples you provided.

 

var doc = app.activeDocument;
var myFolder = doc.filePath;
var jpg_name = doc.name.replace(/.indd$/i, "");


for(var p = 0; p < doc.pages.length; p++) {
var myPageName = doc.pages[p].name;

// Set JPEG export preferences
app.jpegExportPreferences.properties = {
   antiAlias: true,
   embedColorProfile: true,
   exportResolution: 72,
   // exportingSpread: true, // Uncomment if spreads
   jpegColorSpace: JpegColorSpaceEnum.rgb,
   jpegExportRange: ExportRangeOrAllPages.exportRange,
   jpegQuality: JPEGOptionsQuality.maximum,
   jpegRenderingStyle: JPEGOptionsFormat.baselineEncoding,
   useDocumentBleeds: false,
   simulateOverprint: false,
   pageString: myPageName,
 }

 switch (myPageName) {
  case '1':
      var websize = 'email_600x300'; 
      break;
  case '2':
      var websize = 'web_1200x700';  
      break;
 }

doc.exportFile(ExportFormat.jpg,File(myFolder +"/"+ jpg_name + "_" + websize + ".jpg"),false);
}
alert("Done Exporting jpg's!");

 

Regards,

Mike

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 ,
Oct 19, 2021 Oct 19, 2021

Sorry for the late reply, thanks Mike. However I figured it out and here is the script that I ended up with. It works quite well and it can export both PNG and JPG at the same time. 

var myDoc = app.activeDocument;


for(var p = 0; p < app.documents[0].pages.length; p++) {  
  var frames = app.documents[0].pages[p].textFrames;
  var jpg_name = null; 
  

  for(var i = 0; i < frames.length; i++) { 
   try { 
       if(frames[i].paragraphs[0].appliedParagraphStyle.name == 'title') {  
         jpg_name = frames[i].paragraphs[0].contents;  
            break;  
       }
     }catch (e){
   }  
 }
     
 if(jpg_name != null) {  
   
 app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.HIGH; // low medium high maximum

 app.jpegExportPreferences.exportResolution = 72;

 app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.EXPORT_RANGE;
 app.jpegExportPreferences.pageString = app.documents[0].pages[p].name;

 var myDocTitle = myDoc.name.replace(/\.indd$/i,"");
 var myFilePath = myDoc.filePath + "/" + myDocTitle + jpg_name + ".jpg";
 var myFile = new File(myFilePath);
 myDoc.exportFile(ExportFormat.jpg, myFile, false); 
 }
 if (jpg_name == null) { 
 }
}
  
  for(var p = 0; p < app.documents[0].pages.length; p++) {  
        var frames = app.documents[0].pages[p].textFrames;
        var png_name = null; 
        
     
        for(var i = 0; i < frames.length; i++) { 
         try { 
             if(frames[i].paragraphs[0].appliedParagraphStyle.name == 'title2') {  
               png_name = frames[i].paragraphs[0].contents;  
                  break;  
             }
           }catch (e){
         }  
       }
           
       if(png_name != null) {  
         
       app.pngExportPreferences.pngQuality = PNGQualityEnum.HIGH; // low medium high maximum

       app.pngExportPreferences.exportResolution = 72;

       app.pngExportPreferences.pngExportRange = PNGExportRangeEnum.EXPORT_RANGE;
       app.pngExportPreferences.pageString = app.documents[0].pages[p].name;

       var myDocTitle = myDoc.name.replace(/\.indd$/i,"");
       var myFilePath = myDoc.filePath + "/" + myDocTitle + png_name + ".png";
       var myFile = new File(myFilePath);
       myDoc.exportFile(ExportFormat.pngFormat, myFile, false); 
       }
       if (png_name == null) { 
       }
     }
         alert("Done Exporting!");
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
Advisor ,
Oct 20, 2021 Oct 20, 2021

Hello @defaults0afwy5szys8,

 

Hahaha.....I thought that code looked oh so familiar.....

https://community.adobe.com/t5/indesign-discussions/script-exporting-pdf-and-jpg-with-custom-name-fr...

 

Regards,

Mike

 

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 ,
Oct 21, 2021 Oct 21, 2021

I knew your name looked familiar! I've read through so many posts trying to see which script might work and it just happens to be that thread! 

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 21, 2025 Feb 21, 2025

Hi, is there any chance you could explain how to operate this code?  I save it as a .jsx , run it and i get a "Done Exporting" message.
However, i dont know how you designate a title for each page (for it to read) or where it exports to?

Cheers!

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 ,
Feb 21, 2025 Feb 21, 2025
quote

Hi, is there any chance you could explain how to operate this code?  I save it as a .jsx , run it and i get a "Done Exporting" message.
However, i dont know how you designate a title for each page (for it to read) or where it exports to?

 

By @Derrick37705576sgxq

 

The last version of the script - looks for TextFrames with "title" - for JPEG - and "title2" - for PNG - ParaStyle applied to the first paragraph inside.

 

Then uses contents of the paragraph as a suffix to the name of INDD file.

 

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 21, 2025 Feb 21, 2025

It only goes and works!
Brilliant! thanks

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 ,
Feb 21, 2025 Feb 21, 2025
LATEST
quote

It only goes and works!
Brilliant! thanks


By @Derrick37705576sgxq

 

You're welcome.

 

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