Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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 !?
Copy link to clipboard
Copied
You can use the appliedAlternateLayout property of a page to decide whether you want to export it.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
}
}
else
{
alert("No PDF Preset selected");
}
Hope it helps, this works for me !
Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
I'm getting this error:
What am i doing wrong?
Copy link to clipboard
Copied
Hi @ronaldv46449794,
I'm surprised this script ever worked for the people who posted it.
I corrected the version of anthonyoe, which exports an interactive PDF!
Not something I would recommend for PDFs used for printing.
//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)
[modified] 6 January 2021 (changed for-loop of fetching alternative layouts to an one-liner
*/
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.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();
}
For the record ā I changed the first for-loop fetching the alternate layouts.
Copy link to clipboard
Copied
Thanks a lot! I tweaked te script a little bit to get high-res images for print. This works for me!
Copy link to clipboard
Copied
Hi @JK-82,
if you want a PDF for print, I highly recommend changing
ExportFormat.INTERACTIVE_PDF to ExportFormat.PDF_TYPE
and
app.interactivePDFExportPreferences.pageRange to app.pdfExportPreferences.pageRange
All other app.interactivePDFExport... stuff can be removed then.
Copy link to clipboard
Copied
Hi @Jens Trost and @JK-82, this script doesn't seem to work any more. It was the only thing I could find that worked for what I was doing. If there's any chance someone could look into it I would be extremely grateful. Thank you for putting the script together in the first place!
Copy link to clipboard
Copied
This doesnt seem to work anymore
Copy link to clipboard
Copied
Hi @laetitia1127 & @toms44193981
a little bit late in the game but can you please be more specific?
Do you get an error message? If so please share a screenshot. What InDesign version do you use?
I just tried JK's version of the script and it works fine in InDesign 17.4.
Copy link to clipboard
Copied
Oh hi! I appreciate the reply, even if it's been a while! I don't get any error messages at all, it runs the program like normal but the resulting files all contain the entire document, they're not split up. I'm running InDesign 18.4.
Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
@Jens Trost It worked!! That's amazing, you've saved me several hours of work (I have 60 versions of an envelope, each with slight differences on both sides so each version is 2 spreads). Thank you so much for coming back to this post!
Copy link to clipboard
Copied
@Jens Trost I saw your edit and wanted to add, I was exporting with presets for Print pdf files, so it's very possible the Interactive PDF lines were what was causing it to not complete.
Copy link to clipboard
Copied
Hi @Jens Trost ,
I`m having the same problem exporting multiple layouts and the whole discussion helped me a lot, but unfortunately the code is not working here š
Does anyone know how I can fix it?
I'll keep testing the previous scripst posted here, thanks in advance!
Copy link to clipboard
Copied
I GOT IT!!!!
the problem was me š
I was using word to create the file and changing the .docx extension to .jsx manually, so the indesign wasn`t properlly reading the file. I pasted the code in VS Code (online) and saved the file.
Thanks again for the code! Saved me a bunch of time.
Copy link to clipboard
Copied
@Felipe5F89 can you post the .jsx file you're using? It looks like an error in the code itself.
Copy link to clipboard
Copied
@Felipe5F89 nevermind! Always great when it's an easy fix! š