Highlighted

Export via script - multipage WITHOUT creating folder?

New Here ,
Apr 24, 2020

Copy link to clipboard

Copied

I'm using a script popular to these forums which we modified slightly - the goal is to export a multi-page document into two subfolders - one for print and one for digital. The part we're stuck on is that by checking the "Create Separate PDF Files" box in the Pages section of the Export Preset definition, a parent folder is created. We'd like to override this so all PDFs are in the root 'digital' or 'print' folders.

 

Is this possible?

 

Script:

d = app.activeDocument; 
​
// PDF presets 
preset_digital = app.pdfExportPresets.itemByName('Digital Issue PDF'); 
preset_print = app.pdfExportPresets.itemByName('QG Export PDF X1a'); 
​
// checks to see if presets exist
if (!(preset_digital.isValid && preset_print.isValid)){ 
 alert('One of the presets does not exist. Please check spelling carefully.'); 
 exit(); 
}
​
// sets export folder, creates subfolders if they do not exist already
exportFolder = Folder.selectDialog('Select the output folder.');
digitalFolder = new Folder(exportFolder + '/digital/');
  if (!digitalFolder.exists) {digitalFolder.create();}
printFolder = new Folder(exportFolder + '/print/');
  if (!printFolder.exists) {printFolder.create();}
​
// gets name of activeDocument, removes .indd extension, adds suffix and .pdf extension
digitalFilename = String(d.name).replace(/\..+$/, "") + "_T.pdf";
printFilename = String(d.name).replace(/\..+$/, "") + "_QG.pdf";

// export to subfolders
d.exportFile(ExportFormat.PDF_TYPE, new File(exportFolder + '/digital/' + digitalFilename), false, preset_digital); 
d.exportFile(ExportFormat.PDF_TYPE, new File(exportFolder + '/print/' + printFilename), false, preset_print);

 

Topics

How to, Import and export, Scripting

Views

177

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

Export via script - multipage WITHOUT creating folder?

New Here ,
Apr 24, 2020

Copy link to clipboard

Copied

I'm using a script popular to these forums which we modified slightly - the goal is to export a multi-page document into two subfolders - one for print and one for digital. The part we're stuck on is that by checking the "Create Separate PDF Files" box in the Pages section of the Export Preset definition, a parent folder is created. We'd like to override this so all PDFs are in the root 'digital' or 'print' folders.

 

Is this possible?

 

Script:

d = app.activeDocument; 
​
// PDF presets 
preset_digital = app.pdfExportPresets.itemByName('Digital Issue PDF'); 
preset_print = app.pdfExportPresets.itemByName('QG Export PDF X1a'); 
​
// checks to see if presets exist
if (!(preset_digital.isValid && preset_print.isValid)){ 
 alert('One of the presets does not exist. Please check spelling carefully.'); 
 exit(); 
}
​
// sets export folder, creates subfolders if they do not exist already
exportFolder = Folder.selectDialog('Select the output folder.');
digitalFolder = new Folder(exportFolder + '/digital/');
  if (!digitalFolder.exists) {digitalFolder.create();}
printFolder = new Folder(exportFolder + '/print/');
  if (!printFolder.exists) {printFolder.create();}
​
// gets name of activeDocument, removes .indd extension, adds suffix and .pdf extension
digitalFilename = String(d.name).replace(/\..+$/, "") + "_T.pdf";
printFilename = String(d.name).replace(/\..+$/, "") + "_QG.pdf";

// export to subfolders
d.exportFile(ExportFormat.PDF_TYPE, new File(exportFolder + '/digital/' + digitalFilename), false, preset_digital); 
d.exportFile(ExportFormat.PDF_TYPE, new File(exportFolder + '/print/' + printFilename), false, preset_print);

 

Topics

How to, Import and export, Scripting

Views

178

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
Apr 24, 2020 0
Adobe Community Professional ,
Apr 25, 2020

Copy link to clipboard

Copied

exportFile is a sync method if i remember correctly. So a hack would be once the exportFile method returns back you can copy all the contents of the folder inside digital and print to the parent folder and then delete the folder. The pseudo code would be like

  • Export the pdf's in exportFolder/digital folder
  • Find the folder inside exportFolder/digital folder and copy all its content to exportFolder/digital folder
  • Delete the contents of folder found in the second step and then delete the folder as well

-Manan

 

 

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
Reply
Loading...
Apr 25, 2020 0
Adobe Community Professional ,
Apr 25, 2020

Copy link to clipboard

Copied

Try this scripting UI for your reference : 

if(app.documents.length > 0){
    var allPresetNames = [];
    for(var p = 0; p < app.pdfExportPresets.length; p++){
        allPresetNames.push(app.pdfExportPresets[p].name);
        }

    // DIALOG
    // ======
    var dialog = new Window("dialog"); 
        dialog.text = "Export PDF"; 
        dialog.preferredSize.width = 400; 
        dialog.orientation = "column"; 
        dialog.alignChildren = ["left","top"]; 
        dialog.spacing = 10; 
        dialog.margins = 16; 

    var checkbox1 = dialog.add("checkbox", undefined, undefined, {name: "checkbox1"}); 
        checkbox1.text = "Digital PDF"; 
        checkbox1.value = true; 
        
        checkbox1.onClick = function(){
            panel1.enabled = checkbox1.value;
            if(!checkbox3.value && !checkbox1.value){
                button1.enabled = false;
                }
            else{
                button1.enabled = true;
                }
            }

    // PANEL1
    // ======
    var panel1 = dialog.add("panel", undefined, undefined, {name: "panel1"}); 
        panel1.text = "Digital PDF"; 
        panel1.preferredSize.width = 400; 
        panel1.orientation = "column"; 
        panel1.alignChildren = ["left","top"]; 
        panel1.spacing = 10; 
        panel1.margins = 10; 

    // GROUP1
    // ======
    var group1 = panel1.add("group", undefined, {name: "group1"}); 
        group1.preferredSize.width = 350; 
        group1.orientation = "row"; 
        group1.alignChildren = ["left","center"]; 
        group1.spacing = 10; 
        group1.margins = 0; 

    var statictext1 = group1.add("statictext", undefined, undefined, {name: "statictext1"}); 
        statictext1.text = "Select Export Preset : "; 
        statictext1.preferredSize.width = 140; 

    var dropdown1_array = allPresetNames; 
    var dropdown1 = group1.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: dropdown1_array}); 
        dropdown1.selection = 0; 
        dropdown1.preferredSize.width = 228; 

    // GROUP2
    // ======
    var group2 = panel1.add("group", undefined, {name: "group2"}); 
        group2.orientation = "row"; 
        group2.alignChildren = ["left","center"]; 
        group2.spacing = 10; 
        group2.margins = 0; 

    var statictext2 = group2.add("statictext", undefined, undefined, {name: "statictext2"}); 
        statictext2.text = "Suffix for PDF name : "; 
        statictext2.preferredSize.width = 140; 

    var statictext3 = group2.add("statictext", undefined, undefined, {name: "statictext3"}); 
        statictext3.text = "Filename"; 

    var edittext1 = group2.add('edittext {properties: {name: "edittext1"}}'); 
        edittext1.text = "_T"; 
        edittext1.preferredSize.width = 122; 

    var statictext4 = group2.add("statictext", undefined, undefined, {name: "statictext4"}); 
        statictext4.text = ".pdf"; 

    // GROUP3
    // ======
    var group3 = panel1.add("group", undefined, {name: "group3"}); 
        group3.preferredSize.width = 59; 
        group3.orientation = "row"; 
        group3.alignChildren = ["left","center"]; 
        group3.spacing = 10; 
        group3.margins = 0; 
        
    var button1 = group3.add("button", undefined, undefined, {name: "button1"}); 
        button1.text = "Browse"; 

    var edittext2 = group3.add('edittext {properties: {name: "edittext2"}}'); 
        if(app.documents[0].saved){
            edittext2.text = app.documents[0].filePath.fsName.replace(/\\/g,'/'); 
            }
        else{
            edittext2.text = "select folder for output pdf..."; 
            }
        edittext2.preferredSize.width = 296; 

        button1.addEventListener("click",function(event){
            var selectedFolder = "";
            if(app.documents[0].saved){
                selectedFolder = app.documents[0].filePath.selectDlg();
                }
            else{
                selectedFolder = Folder.selectDialog();
                }
            if(selectedFolder!=null){
                edittext2.text = selectedFolder.fsName.replace(/\\/g,'/');
                }
            });

    // GROUP4
    // ======
    var group4 = panel1.add("group", undefined, {name: "group4"}); 
        group4.orientation = "row"; 
        group4.alignChildren = ["left","center"]; 
        group4.spacing = 10; 
        group4.margins = 0; 

    var checkbox2 = group4.add("checkbox", undefined, undefined, {name: "checkbox2"}); 
        checkbox2.text = "Create folder named : "; 
        checkbox2.value = true; 
        checkbox2.preferredSize.width = 150; 
        
        checkbox2.onClick = function(){
            edittext3.enabled = checkbox2.value;
            }

    var edittext3 = group4.add('edittext {properties: {name: "edittext2"}}'); 
        edittext3.text = "Digital"; 
        edittext3.preferredSize.width = 218; 

    // DIALOG
    // ======
    var checkbox3 = dialog.add("checkbox", undefined, undefined, {name: "checkbox3"}); 
        checkbox3.text = "Print PDF"; 
        checkbox3.value = true; 
        
        checkbox3.onClick = function(){
            panel2.enabled = checkbox3.value;
            if(!checkbox3.value && !checkbox1.value){
                button1.enabled = false;
                }
            else{
                button1.enabled = true;
                }
            }

    // PANEL2
    // ======
    var panel2 = dialog.add("panel", undefined, undefined, {name: "panel2"}); 
        panel2.text = "Print PDF"; 
        panel2.preferredSize.width = 400; 
        panel2.orientation = "column"; 
        panel2.alignChildren = ["left","top"]; 
        panel2.spacing = 10; 
        panel2.margins = 10; 

    // GROUP5
    // ======
    var group5 = panel2.add("group", undefined, {name: "group5"}); 
        group5.orientation = "row"; 
        group5.alignChildren = ["left","center"]; 
        group5.spacing = 10; 
        group5.margins = 0; 

    var statictext7 = group5.add("statictext", undefined, undefined, {name: "statictext7"}); 
        statictext7.text = "Select Export Preset : "; 
        statictext7.preferredSize.width = 140; 

    var dropdown2_array = allPresetNames; 
    var dropdown2 = group5.add("dropdownlist", undefined, undefined, {name: "dropdown2", items: dropdown2_array}); 
        dropdown2.selection = 0; 
        dropdown2.preferredSize.width = 228; 

    // GROUP6
    // ======
    var group6 = panel2.add("group", undefined, {name: "group6"}); 
        group6.orientation = "row"; 
        group6.alignChildren = ["left","center"]; 
        group6.spacing = 10; 
        group6.margins = 0; 

    var statictext8 = group6.add("statictext", undefined, undefined, {name: "statictext8"}); 
        statictext8.text = "Suffix for PDF name : "; 
        statictext8.preferredSize.width = 140; 

    var statictext9 = group6.add("statictext", undefined, undefined, {name: "statictext9"}); 
        statictext9.text = "Filename"; 

    var edittext4 = group6.add('edittext {properties: {name: "edittext3"}}'); 
        edittext4.text = "_QG"; 
        edittext4.preferredSize.width = 122; 

    var statictext10 = group6.add("statictext", undefined, undefined, {name: "statictext10"}); 
        statictext10.text = ".pdf"; 

    // GROUP7
    // ======
    var group7 = panel2.add("group", undefined, {name: "group7"}); 
        group7.orientation = "row"; 
        group7.alignChildren = ["left","center"]; 
        group7.spacing = 10; 
        group7.margins = 0; 
        
    var button2 = group7.add("button", undefined, undefined, {name: "button1"}); 
        button2.text = "Browse"; 

    var edittext5 = group7.add('edittext {properties: {name: "edittext2"}}'); 
        if(app.documents[0].saved){
            edittext5.text = app.documents[0].filePath.fsName.replace(/\\/g,'/'); 
            }
        else{
            edittext5.text = "select folder for output pdf..."; 
            }
        edittext5.preferredSize.width = 296; 

        button2.addEventListener("click",function(event){
            var selectedFolder = "";
            if(app.documents[0].saved){
                selectedFolder = app.documents[0].filePath.selectDlg();
                }
            else{
                selectedFolder = Folder.selectDialog();
                }
            if(selectedFolder!=null){
                edittext5.text = selectedFolder.fsName.replace(/\\/g,'/');
                }
            });

    // GROUP8
    // ======
    var group8 = panel2.add("group", undefined, {name: "group8"}); 
        group8.orientation = "row"; 
        group8.alignChildren = ["left","center"]; 
        group8.spacing = 10; 
        group8.margins = 0; 

    var checkbox4 = group8.add("checkbox", undefined, undefined, {name: "checkbox4"}); 
        checkbox4.text = "Create folder named : "; 
        checkbox4.value = true; 
        checkbox4.preferredSize.width = 150; 
        
        checkbox4.onClick = function(){
            edittext6.enabled = checkbox4.value;
            }

    var edittext6 = group8.add('edittext {properties: {name: "edittext4"}}'); 
        edittext6.text = "Print"; 
        edittext6.preferredSize.width = 218; 

    // GROUP9
    // ======
    var group9 = dialog.add("group", undefined, {name: "group9"}); 
        group9.preferredSize.width = 399; 
        group9.orientation = "row"; 
        group9.alignChildren = ["right","center"]; 
        group9.spacing = 10; 
        group9.margins = 0; 

    var button1 = group9.add("button", undefined, undefined, {name: "OK"}); 
        button1.text = "Export"; 

    var button2 = group9.add("button", undefined, undefined, {name: "Cancel"}); 
        button2.text = "Cancel"; 

    if(dialog.show()==1){
        if(checkbox1.value){
            if(Folder(edittext2.text).exists){
                var mainFolderPath = edittext2.text;
                if(checkbox2.value && edittext3.text.replace(/[\s+]/g,'') !=""){
                    if(!Folder(edittext2.text+"/"+edittext3.text).exists){
                        Folder(edittext2.text+"/"+edittext3.text).create();
                        }
                    mainFolderPath = edittext2.text+"/"+edittext3.text;
                    }
                app.documents[0].exportFile(ExportFormat.PDF_TYPE, new File(mainFolderPath + '/' + app.documents[0].name.replace(/\.indd|\.indt/g,'')+edittext1.text+'.pdf'), false, dropdown1.selection.toString()); 
                }
            else{
                alert ("\""+edittext2.text+"\" this folder path doesn't exists or invalid...\nDigital PDF not exported...", "Wrong folder path...", true);
                }
            }
        if(checkbox3.value){
            if(Folder(edittext5.text).exists){
                var mainFolderPath = edittext5.text;
                if(checkbox4.value && edittext6.text.replace(/[\s+]/g,'') !=""){
                    if(!Folder(edittext5.text+"/"+edittext6.text).exists){
                        Folder(edittext5.text+"/"+edittext6.text).create();
                        }
                    mainFolderPath = edittext5.text+"/"+edittext6.text;
                    }
                app.documents[0].exportFile(ExportFormat.PDF_TYPE, new File(mainFolderPath + '/' + app.documents[0].name.replace(/\.indd|\.indt/g,'')+edittext1.text+'.pdf'), false, dropdown2.selection.toString()); 
                }
            else{
                alert ("\""+edittext5.text+"\" this folder path doesn't exists or invalid...\nDigital PDF not exported...", "Wrong folder path...", true);
                }
            }
        alert ("Process completed...", "Completed...", false);
        }
    }
else{
    alert ("Please open a document for processing...", "No document is opened", true);
    }

Best

Sunil

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
Reply
Loading...
Apr 25, 2020 1