Saving PDF using the Layer name

Community Beginner ,
Dec 09, 2020 Dec 09, 2020

Copy link to clipboard

Copied

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?

TOPICS
Feature request, How to, Import and export, Scripting

Views

214

Likes

translate

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

correct answers 2 Correct Answers

Adobe Community Professional , Dec 09, 2020 Dec 09, 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/

Likes

translate

Translate

Translate
Enthusiast , Dec 09, 2020 Dec 09, 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 (v...

Likes

translate

Translate

Translate
Adobe Community Professional ,
Dec 09, 2020 Dec 09, 2020

Copy link to clipboard

Copied

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/

Likes

translate

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 Beginner ,
Dec 09, 2020 Dec 09, 2020

Copy link to clipboard

Copied

Thanks I'll give it a try!

Likes

translate

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
Enthusiast ,
Dec 09, 2020 Dec 09, 2020

Copy link to clipboard

Copied

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

Likes

translate

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 Beginner ,
Dec 09, 2020 Dec 09, 2020

Copy link to clipboard

Copied

Hi Mike!

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

Likes

translate

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
Enthusiast ,
Dec 10, 2020 Dec 10, 2020

Copy link to clipboard

Copied

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

Likes

translate

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 Beginner ,
Dec 10, 2020 Dec 10, 2020

Copy link to clipboard

Copied

var doc = app.activeDocument; var myFolder = doc.filePath; export_preset = app.pdfExportPresets.itemByName("(MODERNA_1v4_IND4)"); 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!');

Likes

translate

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
Enthusiast ,
Dec 10, 2020 Dec 10, 2020

Copy link to clipboard

Copied

I see the preset appears like this in what you posted

export_preset = app.pdfExportPresets.itemByName("(MODERNA_1v4_IND4)");

 

What does the preset look like InDesign??

 

With no square brackets.

export_preset = app.pdfExportPresets.itemByName("MODERNA_1v4_IND4");

 

With square brackets.

export_preset = app.pdfExportPresets.itemByName("[MODERNA_1v4_IND4]");

 

 

Likes

translate

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 Beginner ,
Dec 10, 2020 Dec 10, 2020

Copy link to clipboard

Copied

Okay somehow it is working now. Might have missed a character or something.

But now I noticed I made a mistake in my initial post. The situation is this. 

I have 1 Base layer (images) and 10 language layers. In my current situation what I need is that the script does what it does now but It needs to be able to include any other active layer as well.

Is that at all possible or am I being to difficult?

Likes

translate

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
Enthusiast ,
Dec 10, 2020 Dec 10, 2020

Copy link to clipboard

Copied

Not difficult as long as you can be consistent with the Base layer naming, otherwise you'll need to update the script each time the Base layer name changes.

Likes

translate

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 Beginner ,
Dec 10, 2020 Dec 10, 2020

Copy link to clipboard

Copied

It's always named 

BASE Basis

Likes

translate

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
Enthusiast ,
Dec 10, 2020 Dec 10, 2020

Copy link to clipboard

Copied

Sorry.....

 

BASE Basis?? or BASE?

Likes

translate

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 Beginner ,
Dec 10, 2020 Dec 10, 2020

Copy link to clipboard

Copied

BASE Basis

Likes

translate

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
Enthusiast ,
Dec 10, 2020 Dec 10, 2020

Copy link to clipboard

Copied

Add the line below before the "app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES" line.....

 

doc.layers.item("BASE Basis").visible = true;

 

No need to have the BASE Basis layer active "selected"

 

Regards,

Mike

 

 

Likes

translate

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