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! 😀
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…
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);
}
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…
Yeah your right. It’s a snippit not a readymade script.
Yeah 🙂
But anyway, thanks for suggestion!
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.
Here you can find more info about installing JavaScript snippets:
Hope that helps.
Best,
Marijan.
It looks like the link by ssalcido got lost. Just copy paste the code into the extendscript toolkit http://www.adobe.com/devnet/scripting.html .Select the target app from the pulldown menu on the top and hit the run button. Have a look at this image https://github.com/fabiantheblind/MT4D/raw/gh-pages/images/estk.jpg