Skip to main content
Known Participant
February 21, 2017
Question

Export Each Alternate Layout to Separate PDF?

  • February 21, 2017
  • 6 replies
  • 8338 views

Hi everyone,

I really like the Alternate Layout functionality of ID CC, but find it tedious when I have to export each layout to a separate pdf. Is there an existing way to do this in a batch, or a script that would do this for me, allowing me to choose a PDF Preset also?

Specs:

ID CC 2017

Win10

Thanks in advance for any and all replies!

-Andy

6 replies

New Participant
April 16, 2025

This really saves so much time! I only have one question, and I'm really not good at adjusting scripts myself. I have an InDesign document with multiple layouts, where each layout consists of a cover page, a spread, and a back page. I would like the spread to actually be exported as a spread. I have set the PDF view in the preset to 'Two (cover page)'. But when I open the PDF, they are all separate pages. Does anyone know how I can adjust this in the script?

New Participant
November 6, 2017

Strangely enough (or not so strange considering that this doesn't seem to be common practice), I came upon the same code that tristanc62106920 came across. I got in contact with the original author of the code and he kindly updated it to export interactive PDF files... with some extra options written in the code. Thanks to Oleh, and nice one Tristan - I didn't know enough to modify this myself.

The key difference here is that any interactive PDF, click/hide/show/hyperlink/roll over elements are maintained. This is not possible with a normal 'print preset'.

Same as above, copy or save into .jsx file and install into indesign. Feel free to modify the export setting through the code before exporting a file:

//DESCRIPTION: Export alternative layouts as interactive PDF files

#target indesign

/*

    Here is my solution (actually, not only mine - I found similar script and modified them to make it work the way you need).

This script has been updated for Interactive PDF exporting but still shows a dropdown menu for print presets. Select any preset from the list and press okay to run the script. The PDF preset will be ignored in favour of an interactive PDF export with values selected in the code near the end. Choose JPG compression and PPI

  

    UPDATE:

    There's a chance that any preset settings would not be applied, since    app.interactivePDFExportPreferences (Interacticve PDF) is completly different from the app.pdfExportPreferences (Print PDF)    API: http://www.indesignjs.de/extendscriptAPI/indesign-latest/#InteractivePDFExportPreference.html

      

    If you have suggestions of how to improve this code - feel free to contact me   

    Oleh Melnyk  oleh.melnyk@gmail.com

  

    Change log:

    [created]    5 November 2014

    [modified]   3 August 2017      (export to interactive PDF instaed of print PDF)

    [modified]  18 August 2017     (fix export to interactive PDF - set export page range to app.interactivePDFExportPreferences insteadd of app.pdfExportPreferences)

*/

if(!app.activeDocument.saved){

    var win = new Window('dialog', 'ERROR: Unsaved document');

    win.orientation = 'column';

  

    with(win){

        win.header = add('statictext', undefined, 'You need to save your document (give it a name) before exporting to PDF');      

        win.button = add('button', undefined, 'OK');

    };

    win.show();

    exit();

}

var pagesCount = app.activeDocument.pages.length;

var alternativeLayout = []; // arrays with alternative layouts names

var filePath = app.activeDocument.fullName.fsName;

var fileNameWithPath = filePath.replace(/.indd/, ""); // remove indesign .indd extenstion, as we don't need it

// dirty way to get all alterative layouts names - there should be a better way, but for now I don't know how

for(var i = 0; i < pagesCount; i++){  

    if(alternativeLayout[alternativeLayout.length-1] != app.activeDocument.pages.appliedAlternateLayout.alternateLayout){

        alternativeLayout.push(app.activeDocument.pages.appliedAlternateLayout.alternateLayout);

        i += app.activeDocument.pages.appliedAlternateLayout.alternateLayoutLength-1; // speed up searching for the next alt layout

    }

}

// CORE of the script from here: http://indisnip.wordpress.com/2010/08/02/simple-pdf-export-with-preset-selection/

var presets = app.pdfExportPresets.everyItem().name;

presets.unshift("- Select PDF Preset -");

var win = new Window('dialog', 'PDF Export Presets');

win.orientation = 'row';

with(win){

    win.header = add('statictext', undefined, 'Select PDF Export preset:');

    win.PDFExport = add('dropdownlist',undefined,undefined,{items:presets});

    win.PDFExport.selection = 0;

    win.button = add('button', undefined, 'OK');

};

win.center();

window = win.show();

if(window == true && win.PDFExport.selection.index != 0){

    preset = app.pdfExportPresets.item(String(win.PDFExport.selection));

    for(var alt = 0; alt < alternativeLayout.length; alt++){

        app.interactivePDFExportPreferences.pageRange = alternativeLayout[alt];

    

        app.interactivePDFExportPreferences.pdfMagnification = PdfMagnificationOptions.FIT_PAGE; // General > Viewing > View

        app.interactivePDFExportPreferences.pdfPageLayout = PageLayoutOptions.SINGLE_PAGE; // General > Viewing > Layout

        app.interactivePDFExportPreferences.viewPDF = false; // General > Options > View after exporting

        //app.interactivePDFExportPreferences.pdfRasterCompression = PDFRasterComprestionOptions.JPEG_COMPRESSION; // Compression > Image Compresion > Compresion

        app.interactivePDFExportPreferences.pdfJPEGQuality = PDFJPEGQualityOptions.HIGH; // Compression > Image Compresion > JPEG Quality

        app.interactivePDFExportPreferences.rasterResolution = 100; // Compression > Resolution (ppi)

        app.activeDocument.exportFile(ExportFormat.INTERACTIVE_PDF, (new File(fileNameWithPath + "_" + alternativeLayout[alt] + ".pdf")), false, preset);

    }

}else{

    var win = new Window('dialog', 'ERROR: No PDF Preset selected');

    win.orientation = 'column';

    with(win){

        win.header = add('statictext', undefined, 'You need to select PDF Preset before exporting to PDF');      

        win.button = add('button', undefined, 'OK');

    };

    win.show();

    exit();

}

toms44193981
New Participant
April 19, 2023

This doesnt seem to work anymore

 

New Participant
August 21, 2024

Hi @laetitia1127 

so yea, it depends on what type of PDF you want to export: interactive PDF or a "normal" PDF ... depending on which you want, the script has to use different properties.
JK's version is for interactive pdf. I could be wrong, but using pdfExportPresets with interactive properties and interactive export could cause the issue since you don't have presets when you export interactive PDFs. So there is a mismatch and then InDesign reverts back to exporting everything.

Here is the version for non-interactive PDFs (print and everything else beside interactive) which should work

 

if(!app.activeDocument.saved){
    var win = new Window('dialog', 'ERROR: Unsaved document');
    win.orientation = 'column';

    with(win){
        win.header = add('statictext', undefined, 'You need to save your document (give it a name) before exporting to PDF');
        win.button = add('button', undefined, 'OK');
    };
    win.show();
    exit();
}

var pagesCount = app.activeDocument.pages.length;
var alternativeLayout = []; // arrays with alternative layouts names
var filePath = app.activeDocument.fullName.fsName;
var fileNameWithPath = filePath.replace(/.indd/, ""); // remove indesign .indd extenstion, as we don't need it

var alternativeLayout = app.activeDocument.sections.everyItem().alternateLayout;


// CORE of the script from here: http://indisnip.wordpress.com/2010/08/02/simple-pdf-export-with-preset-selection/
var presets = app.pdfExportPresets.everyItem().name;
presets.unshift("- Select PDF Preset -");

var win = new Window('dialog', 'PDF Export Presets');
win.orientation = 'row';

with(win){
    win.header = add('statictext', undefined, 'Select PDF Export preset:');
    win.PDFExport = add('dropdownlist',undefined,undefined,{items:presets});
    win.PDFExport.selection = 0;
    win.button = add('button', undefined, 'OK');
};

win.center();

var window = win.show();

if(window == true && win.PDFExport.selection.index != 0){
    preset = app.pdfExportPresets.item(String(win.PDFExport.selection));

    for(var alt = 0; alt < alternativeLayout.length; alt++){
        app.pdfExportPreferences.pageRange = alternativeLayout[alt];
        app.activeDocument.exportFile(ExportFormat.PDF_TYPE, (new File(fileNameWithPath + "_" + alternativeLayout[alt] + ".pdf")), false, preset);
    }
} else {
    var win = new Window('dialog', 'ERROR: No PDF Preset selected');
    win.orientation = 'column';

    with(win){
    win.header = add('statictext', undefined, 'You need to select PDF Preset before exporting to PDF');
    win.button = add('button', undefined, 'OK');
    };

    win.show();
    exit();
}

 

 


I just found this and wanted to say thanks! It still works and saves a huge amount of time.

New Participant
November 1, 2017

Hello Guys,

I also found a script that does the job ! Here you go :

Copy the below into a text file then rename it as : ExportAlternativeLayoutsAsPDF.jsx (make sure the .jsx is the extension of the file)

/*

    Here is my solution (actually, not only mine - I found similar script and modified them to make it work the way you need).

    This script ask you to choose PDF Export preset first (you can set necessary settings in:

   

    File > Adobe PDF Presets > Define... dialog box,

    then save preset, and choose it when you run this script).

    Once you choosed Export Preset - click OK,

    Script will save pdf files with your alternative layouts to the same folder where your InDesign file is saved,

    with name of FileName_LayoutName.pdf

       

    If you have suggestions of how to improve this code - feel free to contact me    

    Oleh Melnyk  oleh.melnyk@gmail.com

    5 November 2014

*/

pagesCount = app.activeDocument.pages.length;

alternativeLayout = []; // arrayes with alternative layouts names

fileName = app.activeDocument.name;

filePath = app.activeDocument.fullName.fsName;

fileNameWithPath = filePath.replace(/.indd/, ""); // remove indesign .indd extenstion, as we don't need it

// dirty way to get all alterative layouts names - there should be a better way, but for now I don't know how

for(i = 0; i < pagesCount; i++)

{   

    if(alternativeLayout[alternativeLayout.length-1] != app.activeDocument.pages.appliedAlternateLayout.alternateLayout)

    {

        alternativeLayout.push(app.activeDocument.pages.appliedAlternateLayout.alternateLayout);

    }

}

// CORE of the script from here: http://indisnip.wordpress.com/2010/08/02/simple-pdf-export-with-preset-selection/

presets = app.pdfExportPresets.everyItem().name;

presets.unshift("- Select PDF Preset -");

var win = new Window('dialog', 'PDF Export Presets');

win.orientation = 'row';

with(win){

    win.header = add('statictext', undefined, 'Select PDF Export preset:');

    win.PDFExport = add('dropdownlist',undefined,undefined,{items:presets});

    win.PDFExport.selection = 0;

    win.button = add('button', undefined, 'OK');

    };

win.center();

window = win.show();

if(window == true && win.PDFExport.selection.index != 0)

{

    preset = app.pdfExportPresets.item(String(win.PDFExport.selection));

    for(l = 0; l < alternativeLayout.length; l++)

    {

        app.pdfExportPreferences.pageRange = alternativeLayout;

        app.activeDocument.exportFile(ExportFormat.pdfType, (new File(fileNameWithPath + "_" + alternativeLayout + ".pdf")), false, preset);

    }

}

else

{

    alert("No PDF Preset selected");

}

Hope it helps, this works for me !

Community Expert
October 31, 2017

http://www.kahrel.plus.com/indesign/pdf_individuals.html

This one has an option to export indd files by alternate layout, and you can select the layouts as well. Only thing is that you have to stick the files in a book file, but that's easy enough.

P.

Inspiring
October 31, 2017

You can use the appliedAlternateLayout property of a page to decide whether you want to export it.

New Participant
October 31, 2017

Hi there, i am also trying to find exactly the same answer. I designed a simple log book with 15 different versions so i used alternate layouts. Now its finalised and i just need to export them all at once. It's ok its 15 only but what if i have 80 of them !?