Skip to main content
josephm87551676
Participant
February 20, 2020
Answered

Export multiple PDF files from InDesign document

  • February 20, 2020
  • 1 reply
  • 2509 views

So as mentioned in the title, what I'm requesting is "simple" but I am unable to find a way to do it.

Currently, I am working on a project, for which, I have to:

  • Export the whole Indesign document as a PDF file.
  • Export specific pages to a different PDF file.
  • Export other specific pages to another different PDF file.
  • And so on...

The specific pages range & the PDF file names are always the same

The document is updated on a daily basis, so I have to perform the same tasks many times each day and it's such a waste of time...

 

Please let me know if there is a way to do the same from Adobe Acrobat Pro as well; extracting each defined range of pages to a specific PDF document automatically (meaning that I won't have to specify the pages and the document name each time)

 

Thanks in advance!

Correct answer Sunil Yadav

Try this code for your reference:

if(app.documents.length > 0){
    // DIALOG
    // ======
    var dialog = new Window("dialog"); 
        dialog.text = "Match Object & Move"; 
        dialog.preferredSize.width = 300; 
        dialog.preferredSize.height = 300; 
        dialog.orientation = "column"; 
        dialog.alignChildren = ["center","top"]; 
        dialog.spacing = 10; 
        dialog.margins = 16; 

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

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

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

    var statictext1 = group2.add("statictext", undefined, undefined, {name: "statictext1"}); 
        statictext1.text = "Page Range"; 

    // GROUP3
    // ======
    var group3 = panel1.add("group", undefined, {name: "group3"}); 
        group3.orientation = "row"; 
        group3.alignChildren = ["left","center"]; 
        group3.spacing = 10; 
        group3.margins = 0; 
        
    var pageList = [];
    
    var listbox1 = group3.add ("listbox", undefined, "", {numberOfColumns: 1, showHeaders: true, columnTitles: ["Page Names"], multiselect: true,columnWidths: [250]});
        listbox1.preferredSize.width = 270; 
        listbox1.preferredSize.height = 250; 
        
    var selection = [];
    for(var p = 0; p < app.documents[0].pages.length; p++){
        selection.push(listbox1.add ("item", "Page name : "+app.documents[0].pages[p].name));
        }
    listbox1.selection = selection;
    
    // DIALOG
    // ======
    var divider1 = dialog.add("panel", undefined, undefined, {name: "divider1"}); 
        divider1.alignment = "fill"; 
    
    // GROUP4
    // ======
    var group4 = dialog.add("group", undefined, {name: "group4"}); 
        group4.preferredSize.width = 300; 
        group4.orientation = "row"; 
        group4.alignChildren = ["left","center"]; 
        group4.spacing = 10; 
        group4.margins = 0; 

    var statictext2 = group4.add("statictext", undefined, undefined, {name: "statictext2"}); 
        statictext2.text = "File name : "; 

    var edittext1 = group4.add('edittext {properties: {name: "edittext1"}}'); 
        edittext1.preferredSize.width = 166; 
        edittext1.text = app.documents[0].name.replace(/\.indd/g,'');

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

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

    var statictext2 = group6.add("statictext", undefined, undefined, {name: "statictext3"}); 
        statictext2.text = "Select Preset : "; 
    
    var presetList = [];
    for(var fp = 0; fp < app.pdfExportPresets.length; fp++){
        presetList.push(app.pdfExportPresets[fp].name.toString());
        }
    
    var dropdown1 = group6.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: presetList}); 
        dropdown1.selection = 0; 

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

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

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

    if(dialog.show() == 1){
        var pageRange = [];
        for(var i = 0; i < listbox1.selection.length; i++){
            pageRange +="+"+listbox1.selection[i].toString().replace("Page name : ","");
            }
        app.pdfExportPreferences.pageRange = pageRange;
        var pdfFile = app.documents[0].filePath.fsName.replace(/\\/g,'/')+"/"+edittext1.text.toString()+".pdf";
        if(edittext1.text == ""){
            var pdfFile = app.documents[0].filePath.fsName.replace(/\\/g,'/')+"/"+pageRange.toString()+".pdf";
            }
        app.documents[0].exportFile(ExportFormat.pdfType, pdfFile, false, dropdown1.selection.toString());
        alert ("PDF Exported Successfully !", "Successfully completed !", false);
        }
    else{
        alert ("Have a nice day...!", "Cancelled", false)
        }
    }
else{
    alert ("Please open a file and try again ... !!!", "Warning ... No documents opened!", true)
    }

Best

Sunil

1 reply

Sunil Yadav
Sunil YadavCorrect answer
Legend
February 20, 2020

Try this code for your reference:

if(app.documents.length > 0){
    // DIALOG
    // ======
    var dialog = new Window("dialog"); 
        dialog.text = "Match Object & Move"; 
        dialog.preferredSize.width = 300; 
        dialog.preferredSize.height = 300; 
        dialog.orientation = "column"; 
        dialog.alignChildren = ["center","top"]; 
        dialog.spacing = 10; 
        dialog.margins = 16; 

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

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

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

    var statictext1 = group2.add("statictext", undefined, undefined, {name: "statictext1"}); 
        statictext1.text = "Page Range"; 

    // GROUP3
    // ======
    var group3 = panel1.add("group", undefined, {name: "group3"}); 
        group3.orientation = "row"; 
        group3.alignChildren = ["left","center"]; 
        group3.spacing = 10; 
        group3.margins = 0; 
        
    var pageList = [];
    
    var listbox1 = group3.add ("listbox", undefined, "", {numberOfColumns: 1, showHeaders: true, columnTitles: ["Page Names"], multiselect: true,columnWidths: [250]});
        listbox1.preferredSize.width = 270; 
        listbox1.preferredSize.height = 250; 
        
    var selection = [];
    for(var p = 0; p < app.documents[0].pages.length; p++){
        selection.push(listbox1.add ("item", "Page name : "+app.documents[0].pages[p].name));
        }
    listbox1.selection = selection;
    
    // DIALOG
    // ======
    var divider1 = dialog.add("panel", undefined, undefined, {name: "divider1"}); 
        divider1.alignment = "fill"; 
    
    // GROUP4
    // ======
    var group4 = dialog.add("group", undefined, {name: "group4"}); 
        group4.preferredSize.width = 300; 
        group4.orientation = "row"; 
        group4.alignChildren = ["left","center"]; 
        group4.spacing = 10; 
        group4.margins = 0; 

    var statictext2 = group4.add("statictext", undefined, undefined, {name: "statictext2"}); 
        statictext2.text = "File name : "; 

    var edittext1 = group4.add('edittext {properties: {name: "edittext1"}}'); 
        edittext1.preferredSize.width = 166; 
        edittext1.text = app.documents[0].name.replace(/\.indd/g,'');

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

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

    var statictext2 = group6.add("statictext", undefined, undefined, {name: "statictext3"}); 
        statictext2.text = "Select Preset : "; 
    
    var presetList = [];
    for(var fp = 0; fp < app.pdfExportPresets.length; fp++){
        presetList.push(app.pdfExportPresets[fp].name.toString());
        }
    
    var dropdown1 = group6.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: presetList}); 
        dropdown1.selection = 0; 

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

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

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

    if(dialog.show() == 1){
        var pageRange = [];
        for(var i = 0; i < listbox1.selection.length; i++){
            pageRange +="+"+listbox1.selection[i].toString().replace("Page name : ","");
            }
        app.pdfExportPreferences.pageRange = pageRange;
        var pdfFile = app.documents[0].filePath.fsName.replace(/\\/g,'/')+"/"+edittext1.text.toString()+".pdf";
        if(edittext1.text == ""){
            var pdfFile = app.documents[0].filePath.fsName.replace(/\\/g,'/')+"/"+pageRange.toString()+".pdf";
            }
        app.documents[0].exportFile(ExportFormat.pdfType, pdfFile, false, dropdown1.selection.toString());
        alert ("PDF Exported Successfully !", "Successfully completed !", false);
        }
    else{
        alert ("Have a nice day...!", "Cancelled", false)
        }
    }
else{
    alert ("Please open a file and try again ... !!!", "Warning ... No documents opened!", true)
    }

Best

Sunil

josephm87551676
Participant
February 20, 2020

Hi @Sunil_Yadav1 and thank you for your reply.

Unfortunately, I have no experience with scripting or code. I was hoping for a simpler way to do this, directly from the software UI / toolbar functions.

Sunil Yadav
Legend
February 20, 2020

You can copy this code and paste in text document and save it as File.jsx put this file in Application Folder-> Script->Script panel Folder, then you can see that in the list of Script in Window->Utilities->Scripts.

 

From there you can double click it, it will run.

 

Refer this link for your information:

https://community.adobe.com/t5/indesign/how-to-change-a-specific-objects-settings-across-all-pages/m-p/10928514?page=1#M175682

 

Best

Sunil