Skip to main content
Known Participant
August 8, 2022
Answered

Layered InDesign Export Script

  • August 8, 2022
  • 12 replies
  • 2310 views

Hi there, 

 

I'm looking for a script that will help me export one layered InDesign in multiple variations at once. This is to generate product info sheets where the contact information (and some of the product data) is different dependent on country.

 

The build will be something like this…

Layer 1: Parent content — should be used in conjunction with all other layers (think logo, title etc).

Layer 2 to 10*: Country 1 version (with address etc in footer as well as localised content)

 

*This could be any number, right now I'm looking at 3 separate versions, but this will grow.

 

Ideally, the export would export Layer 1 and Layer 2 as one PDF (with the name of Layer 2 at the end of the file name), Layer 1 and Layer 3 as a second PDF, Layer 1 and Layer 4 as a third PDF etc etc.

 

So if I had Layer 1 plus 3 other layers, I'd end up with 3 separate PDFs.

 

I'd also like to export by spread using the product name (which would always be on Layer 1) as the first half of the file name.

 

Finally, if the Layer 3 (for example) is empty for one spread, I'd like to skip that spread in the export. 

 

Side note, I could of course manually export by switching layers on and off etc. but I'd like to automate this because there are many mannnnny different versions of these files and we're a really small team. Work smart and all that.

 

Does this or something like it exist?

 

Thanks in advance!

Linsey

This topic has been closed for replies.
Correct answer willcampbell7

Have a look at this:

http://www.marspremedia.com/software/indesign/export-layers

Other users asked for similar functionality, so I added features, but I'm not sure if it exactly matches your situation. Maybe. There is the choice in this script to output each unlocked layer combined with all locked layers. So lock the common layers and leave the language layers unlocked. Choose 'Each layer all pages' and you should end up with a PDF for each language. If it doesn't quite work, message me through the contact page on my website. I'll be happy to consider changes (or another script) if this one doesn't quite do it.

 

12 replies

willcampbell7
willcampbell7Correct answer
Legend
August 19, 2022

Have a look at this:

http://www.marspremedia.com/software/indesign/export-layers

Other users asked for similar functionality, so I added features, but I'm not sure if it exactly matches your situation. Maybe. There is the choice in this script to output each unlocked layer combined with all locked layers. So lock the common layers and leave the language layers unlocked. Choose 'Each layer all pages' and you should end up with a PDF for each language. If it doesn't quite work, message me through the contact page on my website. I'll be happy to consider changes (or another script) if this one doesn't quite do it.

 

William Campbell
Known Participant
August 25, 2022

Hi William, 

 

Thanks so much for your message. I've dropped you a message via your website. 

 

Thanks again!

Linsey

willcampbell7
Legend
August 25, 2022

Thanks for the messages, and extra thanks for revealing the bug recently introduced when fixing another bug (the life of a software developer is a neverending challenge). I'm pleased to hear the script now works to get the output you need. That makes my day.

 

William Campbell
Known Participant
August 15, 2022

Bumping to see if anyone has any insights on this. I've been trying bits and bobs, but I'm no expert!

Legend
August 8, 2022

Hello @linseyblack,

 

Check the post below for a script I wrote...I'm also attaching it here.

https://community.adobe.com/t5/indesign-discussions/export-mutations-with-several-different-layers/m-p/11786148#M411986

 

var doc = app.activeDocument;
var myFolder = doc.filePath;

export_preset = app.pdfExportPresets.itemByName("[High Quality Print]");

if (!(export_preset.isValid)){ 
    alert('The PDF export preset does not exist.'); 
    exit(); 
   }

function myGetVisibleLayers(){
 var myVisibleLayers = new Array;
  for (var i = 0; i < doc.layers.length; i++){
   if (doc.layers[i].visible == true) {   
    myVisibleLayers.push(doc.layers[i].index);
      }
   }
      return myVisibleLayers;
  }

 //Layers Manager Dialog/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  var layerNames = [];

   for (var i = 0; i < doc.layers.length; i++) {
   layerNames.push(doc.layers[i].name);
   }
   var myW = new Window ("dialog", "Layers Manager"), 
   layerGroup = myW.add("group");
   layerGroup.alignChildren = "row";
   var columns = myW.add("group"); columns.spacing=20;
   
   layerGroup.add ('statictext', [-55,28,200, 43], "Select Base Layer(s)");
   var base = columns.add ("listbox", [30, 0, 275, 300] , layerNames, {multiselect: true});
   base.revealItem (doc.layers.length -i/1);
   var selectedBase = []; 
   for (var i = 0; i < base.items.length; i++){selectedBase[0] = base.items[i];}
   base.selection = selectedBase; 

   layerGroup.add ('statictext', [365, 28,603,43], "Select Version Layer(s)");   
   var versions = columns.add ("listbox", [30, 0, 275, 300] , layerNames, {multiselect: true});
   versions.revealItem (doc.layers.length -i/1);   
   var selected = []; 
   for (var i = 0; i < versions.items.length-1; i++){selected[i] = versions.items[i];}
   versions.selection = selected;

   var btn = myW.add("group");
   btn.orientation = "row";
   btn.alignment = ["right", "top"];
   var cancelBtn = btn.add ("button", undefined, "Cancel", {name:"Cancel"});
   var okBtn = btn.add ("button", undefined, "OK", {name:"OK"});
   
   var myResult = myW.show()   
   if(myResult == 1){  
   main();  
   }  
   else if (myResult== 2){  
   exit(0);  
   }  
   function main(){ 

///pdf /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

   if (base.selection == null){
  alert ('Error!\nNo base layer was selected for pdf Output. Please try again.') 
  exit();
  }
  else if (versions.selection == null){
  alert ('Error!\nNo version layers(s) were selected for pdf Output. Please try again.')
  exit();
  }
 var lookup = {};
 for (var j in versions.selection) {lookup[versions.selection[j]] = versions.selection[j];}
 for (var i in base.selection) {
 if (typeof lookup[base.selection[i]] != 'undefined'){
 alert('The layer "'+ [base.selection[i]] + '" cannot be both a base and version layer.\nPlease try again.');
 exit ();
 break;
 } 
 }

 var myVisibleLayers = myGetVisibleLayers();
      
  doc.layers.everyItem().visible = false;

  for (var i = 0; i < base.selection.length; i++){
  var myBase = base.selection[i].index;

  doc.layers[myBase].visible =  true; 
  }

  for (var i = 0; i < versions.selection.length; i++){
  var myVersion = versions.selection[i].index;

  var my_layer = doc.layers[myVersion].name;

  doc.layers[myVersion].visible = true;
  
  app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES

  doc.exportFile(ExportFormat.PDF_TYPE, File(myFolder +'/'+ my_layer + ".pdf"), false, export_preset);

  doc.layers[myVersion].visible = false;
}
  doc.layers.everyItem().visible = false;

  for (var i = 0; i < myVisibleLayers.length; i++){  
    var myLayers = myVisibleLayers[i];
    doc.layers[myLayers].visible =  true; 
    }
    alert('Done Exporting the selected Layers to a PDF!');
}

Regards,

Mike

Known Participant
August 8, 2022

Hi Mike,

This is really helpful, thanks. I'm looking for a way to add that each spread should be exported as a separate PDF but in single page view, if you could point me in the right direction? (I have a PDF export preset which includes Single Pages if that helps?)

Thanks!
Linsey

<personal info removed>

Community Expert
August 9, 2022

(I removed some of your personal info, if you can remember to turn off your email signature if replying by email, thanks)