Home > HOT Posts!, InDesign Scripts > Simple PDF Export with Preset selection

Simple PDF Export with Preset selection

I’ve made small simple script for exporting document to PDF using preset we select. We will see how to list PDF Export Presets we have available, select output file, and export file. So, let’s get started! 😀

First, how to list avaliable PDF Export Presets? It’s pretty easy thanks to everyItem() property. Here is the code:

var myPresets = app.pdfExportPresets.everyItem();

Good, now we have Object with all PDF Export Presets. Now we can extract name or other preferences like this:

var myPresetName = myPresets.name[0];

Or for example Acrobat Compatibility:

var myPresetCompatibility = myPresets.acrobatCompatibility[0];

Ok, this is cool, but we want to populate drop-down box with preset names, and there is really easy to do:

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

What we did is we extracted Name property from every preset avaliable. Now myPresets holds array of preset names, so we can populate drop-down box. One thing I did, is to add drop-down item with custom text in front of all presets. There is one great Array function in Javascript to add item on beginning.

myPresets.unshift("- Select Preset -");

Good. Now, we create window, with some text, drop-down box, and OK button. We populate drop-down box with myPresets like this:

myWin.myPDFExport = add('dropdownlist',undefined,undefined,{items:myPresets});

Ok, if preset is selected, we go to choosing where we want to save file. After that, we export file like this:

app.activeDocument.exportFile(ExportFormat.PDF_TYPE, myFile, false, myPreset);

You probably noticed ‘false‘ parameter. If it’s ‘false‘ then Export options will not be shown and vice versa. We passed file we selected and myPreset to exportFile.

var myPresets = app.pdfExportPresets.everyItem().name;
myPresets.unshift("- Select Preset -");

var myWin = new Window('dialog', 'PDF Export Presets');
myWin.orientation = 'row';
	myWin.sText = add('statictext', undefined, 'Select PDF Export preset:');
	myWin.myPDFExport = add('dropdownlist',undefined,undefined,{items:myPresets});
	myWin.myPDFExport.selection = 0;
	myWin.btnOK = add('button', undefined, 'OK');
var myWindow = myWin.show();

if(myWindow == true && myWin.myPDFExport.selection.index != 0){
    var myPreset = app.pdfExportPresets.item(String(myWin.myPDFExport.selection));
    myFile = File(File.saveDialog("Save file with preset: " + myPreset.name,"PDF files: *.pdf"));
    if(myFile != null){
        app.activeDocument.exportFile(ExportFormat.PDF_TYPE, myFile, false, myPreset);
        alert("No File selected");
    alert("No PDF Preset selected");

That’s it. On thing we can do is to select page range for exporting file like this:

app.pdfExportPreferences.pageRange = "1-4,7";

If we insert this line between line 18 and 19, script will export pages 1 to 4 and page 7. Easy and effective.

Have fun! 😀

  1. Igor Souza
    March 5, 2012 at 20:08

    Thank you! You brought in a short and easy post the info that i need, details, examples and good ideas!
    Can i use radio buttons to choose between “All pages” and “Pages:”? Then when “Pages:” is selected a text field is activated to the input of the pages (1-4,7…)

    • June 11, 2012 at 21:10

      Of course you can!
      It would be something like InDesign already have implemented.


  1. August 2, 2010 at 15:58

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: