Skip to main content
Known Participant
December 9, 2020
Answered

Saving PDF using the Layer name

  • December 9, 2020
  • 2 replies
  • 1856 views

Right now Indesign gives you the option to use the document name as the export documentname.

But I'd like to have the option or a script that enables me to do an export of the active layer and it automatically using the layers name. Does anyone have an idea how to achieve this?

This topic has been closed for replies.
Correct answer Mike Bro

Hello Mitchel,

 

The below script will export a pdf of the initial "selected" active layer. The pdf will be named by the layer name and exported to the same location as the InDesign Document.

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

var myVisibleLayers = myGetVisibleLayers();

myActiveLayerName = doc.activeLayer.name;
myActiveLayerIndex = doc.activeLayer.index;

  doc.layers.everyItem().visible = false;

  doc.layers[myActiveLayerIndex].visible = true; 

  app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES

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

  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 Layer '+'"'+ myActiveLayerName +'"'+ ' to a PDF!');

 

Regards,

Mike

2 replies

Mike BroCorrect answer
Legend
December 10, 2020

Hello Mitchel,

 

The below script will export a pdf of the initial "selected" active layer. The pdf will be named by the layer name and exported to the same location as the InDesign Document.

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

var myVisibleLayers = myGetVisibleLayers();

myActiveLayerName = doc.activeLayer.name;
myActiveLayerIndex = doc.activeLayer.index;

  doc.layers.everyItem().visible = false;

  doc.layers[myActiveLayerIndex].visible = true; 

  app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES

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

  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 Layer '+'"'+ myActiveLayerName +'"'+ ' to a PDF!');

 

Regards,

Mike

Known Participant
December 10, 2020

Hi Mike!

I tried the script but it throws a "The PDF export preset does not exist" message.

Legend
December 10, 2020

Hello Mitchel,

Do you not have the preset [High Quality Print] on your machine? It not you can edit the script and use whatever preset you like.

Just know it must be written just as it appears in InDesign with or without the square brackets.

 

Maybe post the preset you would like to use and I can repost the code.

 

Regards,

Mike

brian_p_dts
Community Expert
Community Expert
December 9, 2020

Maybe try Page Exporter Utility script to see if it can solve your needs: 

https://creativepro.com/page-exporter-utility-peu-5-script-updated-for-cs3/

Known Participant
December 10, 2020

Thanks I'll give it a try!