One script to export multiple document types/outcomes

New Here ,
Jul 06, 2021 Jul 06, 2021

Copy link to clipboard

Copied

I have a double page document for instructions - sometimes they can be single page instructions and other times they can be two pages. I need them exported in 3 different ways:

 

Standard - Single pages (one or two)

2UP - Double page spread (regardless of whether there is one or two pages because we print two pages onto an A4 sheet and then cut in half when printed in house)

With Bleed - Single pages (one or two) with bleed (when printed professionally)

 

I currently have 3 Adobe PDF presets for each of the above and a script which runs them all at the same time to then export into a single place so the outcome is 3 separate PDFs of the 3 outcomes I need.

 

The only issue is that it will always export 2 pages (the single page documents have the same duplicated on second page for the '2UP' version). So I basically have the correct script if the documents are two pages but I have to go back and delete for any document that is only a single page (which is the majority).

 

Below is the script example:

 

// BS"D 
// All rights reserved (c) 2015 by Id-Extras.com 
// Free to use and modify but do not delete this copyright attribution. 
// This script will export 2 pdfs of the current document 
// Choose the PDF presets by altering their names below 
// The second PDF gets a suffix added to its name. 
// Modify the line below beginning name2 = to change the suffix. 
// For more InDesign scripts: www.Id-Extras.com 
d = app.activeDocument; 
// Here you can choose the PDF preset 
preset1 = app.pdfExportPresets.itemByName("Instructions_Standard"); 
preset2 = app.pdfExportPresets.itemByName("Instructions_With_Bleed");
preset3 = app.pdfExportPresets.itemByName("Instructions_2UP");
if (!(preset1.isValid && preset2.isValid)){ 
 alert("One of the presets does not exist. Please check spelling carefully."); 
 exit(); 
} 
if (d.saved){ 
 thePath = String(d.fullName).replace(/\..+$/, "") + ".pdf"; 
 thePath = String(new File(thePath).saveDlg()); 
} 
else{ 
 thePath = String((new File).saveDlg()); 
} 
thePath = thePath.replace(/\.pdf$/, ""); 
name1 = thePath+".pdf"; 
// Here you can set the suffix at the end of the name 
name2 = thePath+"_with_bleed.pdf";
name3 = thePath+"_2UP.pdf";
d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1); 
d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
d.exportFile(ExportFormat.PDF_TYPE, new File(name3), false, preset3);// JavaScript Document

 

 I have two ideas on how to get around this but cannot seem to work it out.

 

1. Create a second script which will remove the second page from the 'standard' and 'with_bleed' PDF.

 

or

 

2. Create a second (different) script which doesn't need to use the Adobe PDF presets and the settings will be within the script - I'm not sure if that is possible.

 

It might also be worth saying that I have tried to change the Adobe PDF presets to only export a page range but for some reason it does not allow this and that section in the pop up screen is greyed out and I cannot work out how to change it.

 

Any help or ideas would be great!

 

Thank you,

Dave

TOPICS
How to, Import and export, Scripting

Views

66

Likes

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 1 Correct answer

Advocate , Jul 06, 2021 Jul 06, 2021
Hello @default9teisv3sf5yt You can contol the pdf page range with the pdf Export Preferences and creating a simple dialog with a couple of radio buttons for the output options. I think I understood what you're after so give the below script a try... var dialog = new Window("dialog"); dialog.text = "Export Instructions"; dialog.orientation = "column"; dialog.alignChildren = ["right","top"]; dialog.spacing = 10; dialog.margins = 16; var MyPanel = dialog.add("panel", und...

Likes

Translate

Translate
Advocate ,
Jul 06, 2021 Jul 06, 2021

Copy link to clipboard

Copied

Hello @default9teisv3sf5yt 

You can contol the pdf page range with the pdf Export Preferences and creating a simple dialog with a couple of radio buttons for the output options. I think I understood what you're after so give the below script a try...

 

 

var dialog = new Window("dialog"); 
    dialog.text = "Export Instructions"; 
    dialog.orientation = "column"; 
    dialog.alignChildren = ["right","top"]; 
    dialog.spacing = 10; 
    dialog.margins = 16; 

var MyPanel = dialog.add("panel", undefined, undefined, {name: "MyPanel"}); 
    MyPanel.preferredSize.width = 167; 
    MyPanel.orientation = "column"; 
    MyPanel.alignChildren = ["left","top"]; 
    MyPanel.spacing = 10; 
    MyPanel.margins = 10; 

var ExportAllPages = MyPanel.add("radiobutton", undefined, undefined, {name: "ExportAllPages"}); 
    ExportAllPages.text = "Export all pages for all formats"; 

var ExportPage1Only = MyPanel.add("radiobutton", undefined, undefined, {name: "ExportPage1Only"}); 
    ExportPage1Only.text = "Export page 1 only for Standard & Bleed"; 
    ExportPage1Only.value = true; 

var OKCancelGroup = dialog.add("group", undefined, {name: "OKCancelGroup"}); 
    OKCancelGroup.orientation = "row"; 
    OKCancelGroup.alignChildren = ["left","center"]; 
    OKCancelGroup.spacing = 10; 

var Cancel = OKCancelGroup.add("button", undefined, undefined, {name: "Cancel"});
    Cancel.text = "Cancel"; 
    Cancel.preferredSize.width = 69; 

var OK = OKCancelGroup.add("button", undefined, undefined, {name: "OK"});
    OK.text = "OK"; 
    OK.preferredSize.width = 69;

var result = dialog.show();

if(result == 1){

d = app.activeDocument; 
preset1 = app.pdfExportPresets.itemByName("Instructions_Standard"); 
preset2 = app.pdfExportPresets.itemByName("Instructions_With_Bleed");
preset3 = app.pdfExportPresets.itemByName("Instructions_2UP");

if (!(preset1.isValid && preset2.isValid)){ 
alert("One of the presets does not exist. Please check spelling carefully."); 
exit(); 
} 
try {if (d.saved){ 
thePath = String(d.fullName).replace(/\..+$/, "") + ".pdf"; 
thePath = String(new File(thePath).saveDlg()); 
} else {  
thePath = String((new File).saveDlg()); 
} 

thePath = thePath.replace(/\.pdf$/, ""); 
name1 = thePath+".pdf"; 
name2 = thePath+"_with_bleed.pdf";
name3 = thePath+"_2UP.pdf";

if(ExportPage1Only.value == true){
app.pdfExportPreferences.pageRange = "1-1"
d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1); 
d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
app.pdfExportPreferences.pageRange = "1-2"
d.exportFile(ExportFormat.PDF_TYPE, new File(name3), false, preset3);
}
    
if(ExportAllPages.value == true){
app.pdfExportPreferences.pageRange = "1-2"
d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1); 
d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
d.exportFile(ExportFormat.PDF_TYPE, new File(name3), false, preset3);
}
alert("Done Exporting PDF's!");

  } catch (e){
 } 
}
   
if (result == 2){   
exit();  
}

 

 

Regards,

Mike

Likes

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
New Here ,
Jul 07, 2021 Jul 07, 2021

Copy link to clipboard

Copied

LATEST

@mikeb41294032thank you!

 

That was more than what I was looking for and works perfectly.

 

I really appreciate your help!

 

Dave

 

 

Likes

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