Highlighted

Export named JPG thumbnails from InDesign

New Here ,
Jul 28, 2020

Copy link to clipboard

Copied

First post, so please be gentle!

 

I'm an InDesign user on Windows 10.

 

Here's my predicament.

I'm using DataMerge to create a large batch of thumbnails in InDesign.

The each thumbnail is composed of 3 elements - a main image - a seconday image, and a line of text (a name).

I'm using DataMerge because I'm not sure if there's anything else out there that would do a better job.

However - once these thumbs have been exported, I'm currently having to rename them all by hand - which I'm doing in Lightroom - again, because it's the easiest way of doing it.

But is there something out there - a plugin, or a script, or something, to do this for me to save a ton of time - or can it all be done from inside InDesign (which would maybe be the best option given that I've got the datamerge process working well)?

I'm already creating a csv file to drive the production of the thumbs - why can't I use this csv to name each thumbnail as well?
I'd like to be able to use the "name" column in my CSV file to name each subsequent page - but don't know if there's a way to do it - or even if it can be done.

 

Any advice on this would be REALLY appreciated!

Hello,

 

I'm working on a MacBook and it appeared to be working fine for me without any errors, but I shoud have looked a bit closer at the final output. I also added a check to ensure all pages have the Paragraph Style named "filename"applied to a text frame.  The code below shoud work for you now.

var doc = app.documents[0];

var mySelectedFolder = Folder.selectDialog ("Select a Folder");
 if(mySelectedFolder != null){

}else{
exit();
}

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 == 'filename') {  
                jpg_name = frames[i].paragraphs[0].contents;  
                   break;  
              }
            }catch (e){
          }  
        }

        if (jpg_name == null) { 
          alert ('Error!\nThe Paragraph Style "filename" is not applied to one or more of the pages or is Labeled Incorrectly.');
          exit();
          }
            
        if(jpg_name != null) {  
          
        app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.LOW; // low medium high maximum

        app.jpegExportPreferences.exportResolution = 72;

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

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

    

Regards,

Mike

TOPICS
Feature request, How to, Scripting

Views

119

Likes

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

Export named JPG thumbnails from InDesign

New Here ,
Jul 28, 2020

Copy link to clipboard

Copied

First post, so please be gentle!

 

I'm an InDesign user on Windows 10.

 

Here's my predicament.

I'm using DataMerge to create a large batch of thumbnails in InDesign.

The each thumbnail is composed of 3 elements - a main image - a seconday image, and a line of text (a name).

I'm using DataMerge because I'm not sure if there's anything else out there that would do a better job.

However - once these thumbs have been exported, I'm currently having to rename them all by hand - which I'm doing in Lightroom - again, because it's the easiest way of doing it.

But is there something out there - a plugin, or a script, or something, to do this for me to save a ton of time - or can it all be done from inside InDesign (which would maybe be the best option given that I've got the datamerge process working well)?

I'm already creating a csv file to drive the production of the thumbs - why can't I use this csv to name each thumbnail as well?
I'd like to be able to use the "name" column in my CSV file to name each subsequent page - but don't know if there's a way to do it - or even if it can be done.

 

Any advice on this would be REALLY appreciated!

Hello,

 

I'm working on a MacBook and it appeared to be working fine for me without any errors, but I shoud have looked a bit closer at the final output. I also added a check to ensure all pages have the Paragraph Style named "filename"applied to a text frame.  The code below shoud work for you now.

var doc = app.documents[0];

var mySelectedFolder = Folder.selectDialog ("Select a Folder");
 if(mySelectedFolder != null){

}else{
exit();
}

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 == 'filename') {  
                jpg_name = frames[i].paragraphs[0].contents;  
                   break;  
              }
            }catch (e){
          }  
        }

        if (jpg_name == null) { 
          alert ('Error!\nThe Paragraph Style "filename" is not applied to one or more of the pages or is Labeled Incorrectly.');
          exit();
          }
            
        if(jpg_name != null) {  
          
        app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.LOW; // low medium high maximum

        app.jpegExportPreferences.exportResolution = 72;

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

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

    

Regards,

Mike

TOPICS
Feature request, How to, Scripting

Views

120

Likes

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
Jul 28, 2020 0
Engaged ,
Jul 28, 2020

Copy link to clipboard

Copied

Hello dev@subharmonic.co.uk

Yes it can be done!

Create a Paragraph Style named "filename" and apply it to the text frame that you will be assigning the "name" column from your CSV file. After you do the Data Merge run the script below to export the .jpg files named by the contents of each text frame.

If you need to add additional jpegExportPreferences you can refer to this link.

https://www.indesignjs.de/extendscriptAPI/indesign-latest/index.html#JPEGExportPreference.html

 

 

 

 

var doc = app.documents[0];

var mySelectedFolder = Folder.selectDialog ("Select a Folder");
 if(mySelectedFolder != null){

}else{
exit();
}

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 == 'filename') {  
                jpg_name = frames[i].paragraphs[0].contents;  
                   break;  
              }
            }catch (e){
          }  
        }
    
        app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.HIGH; // low medium high maximum

        app.jpegExportPreferences.exportResolution = 72;

        app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;

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

    

 

 

Regards,

Mike

 

 

Likes

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
Reply
Loading...
Jul 28, 2020 2
New Here ,
Jul 29, 2020

Copy link to clipboard

Copied

Mike - thanks for your input - it's really appreciated!

 

However - I can't get it to work for some reason. (I'm a bit of a scripty noob).

I get the following error.

"Failed to export the JPG file: Specify a page number".

 

Do I need to change the script in some way?

What am I doing wrong?

Likes

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
Reply
Loading...
Jul 29, 2020 0
Engaged ,
Jul 29, 2020

Copy link to clipboard

Copied

Hello,

 

I'm working on a MacBook and it appeared to be working fine for me without any errors, but I shoud have looked a bit closer at the final output. I also added a check to ensure all pages have the Paragraph Style named "filename"applied to a text frame.  The code below shoud work for you now.

var doc = app.documents[0];

var mySelectedFolder = Folder.selectDialog ("Select a Folder");
 if(mySelectedFolder != null){

}else{
exit();
}

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 == 'filename') {  
                jpg_name = frames[i].paragraphs[0].contents;  
                   break;  
              }
            }catch (e){
          }  
        }

        if (jpg_name == null) { 
          alert ('Error!\nThe Paragraph Style "filename" is not applied to one or more of the pages or is Labeled Incorrectly.');
          exit();
          }
            
        if(jpg_name != null) {  
          
        app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.LOW; // low medium high maximum

        app.jpegExportPreferences.exportResolution = 72;

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

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

    

Regards,

Mike

Likes

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
Reply
Loading...
Jul 29, 2020 2
New Here ,
Jul 29, 2020

Copy link to clipboard

Copied

Mike - IT WORKED!!!!!!!!!!!!!

UNBELIEVABLE!!!!!!!!!

 

You are a star mate. Really - this is wild.

 

Thanks ever so much for your help.

 

OUTSTANDING!

Likes

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
Reply
Loading...
Jul 29, 2020 0