Home > HOT Posts!, InDesign Scripts > Export selection to JPEG

Export selection to JPEG

I think that title already says everything about this post😀 and I’ll try to be short. When you are exporting from InDesign GUI you have option to export just selected objects, but how to achieve this from script?😕 This script is also published on Adobe’s InDesign scripting forum.

We know that we can export things from InDesign like this: app.exportFile();, but, that exports entire document, or selected pages, and how to export just selected items? First, PDF doesn’t allow us to export selection, I only tested this script with JPEG! Feature that allows us to export selected object to JPEG is: app.selection[0].exportFile();. If our selection contains more than one object, this command will export just first object from selection, so we must first group selected objects, and then export selected group. And at the end, if we group objects from multiple layers, objects are moved to one layer, and if we ungroup objects after export, they are not returned to layers they belong, so best way is just to undo grouping operation. And here is the code:

if(app.selection.length > 1){
    var myObj = app.activeWindow.activePage.groups.add(app.selection);
    myObj.exportFile(ExportFormat.JPG, myFile, false);
    app.activeDocument.undo();
}else{
    app.selection[0].exportFile(ExportFormat.JPG, myFile, false);
}

Yeah, this is really handy little snippet🙂

Have fun!😀

  1. User
    October 13, 2010 at 21:25

    In old good times when apps was no fancy but usefull there was plugin from ALAP called InPrint, which allowed you export to jpg/tiff/idd any visible part of document with just mouse draw… Shame it is not av. anymore…

  2. October 28, 2010 at 09:13

    Hi, thanx for the snippit. But it doesent work (under CS5);(
    The variable myFile is missing. I *rewrote it a bit.


    if(app.selection.length > 1){
    var myFile = File("~/Desktop/myTest.jpg");
    var myDoc = app.activeDocument;

    var myPage = myDoc.pages.item(0);
    var myGroup = myPage.groups.add(app.selection);
    myDoc.exportFile(ExportFormat.JPG, myFile, false);
    app.activeDocument.undo();
    }else{
    app.selection[0].exportFile(ExportFormat.JPG, myFile, false);
    }

    • October 28, 2010 at 10:09

      Hey!

      Well, the thing is that I intentionally leaved that part with declaring variables so that you can define file name from document name or what ever you want to do…

      • October 28, 2010 at 10:39

        Yeah your right. It’s a snippit not a readymade script.

      • October 28, 2010 at 11:19

        Yeah🙂
        But anyway, thanks for suggestion!

    • January 31, 2012 at 22:18

      Hi,

      This is a rookie question, I know, but how do you actually “install” or use this snippet. I tried copy paste on AppleScript Editor but I doesn’t work.

      I’m not a programmer so I’d like to know how to activate this inside InDesign, because isn’t like a readymade script you can just copy inside the scripts folder.

      Thanks a lot.

  1. No trackbacks yet.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: