
Copy link to clipboard
Copied
Hello,
From InDesign, I can select a group/textFrame/pictureFrame, and then click File -> Export. From this dialog, after I select my "save location," I can then choose to "Export Selection" by selecting the "Selection" radio button.
I'm wondering if this is possible to do with a script? The reason I ask is because I need to export single picture frames (actually, grouped frames, there will be text frames grouped with picture frames). In the SDK I see exportFile() options where you can select if you wish to export as PDF, IDML, JPG, etc. But nothing on "exporting selection". Does anyone know if this is possible, and if so, how it is done?
I know there is a bool you can set to "true" to display the dialog, but this all needs to be automated. Anyone have any thoughts on this?
Thanks in advance!
-Lloyd
1 Correct answer
Hey!
Maybe you can try this code:
var myFile = File('/c/myTest.jpg');
if(app.selection.length > 1){
var myObj = app.activeWindow.activePage.groups.add(app.selection);
myObj.exportFile(ExportFormat.JPG, myFile, false);
myObj.ungroup();
}else{
app.selection[0].exportFile(ExportFormat.JPG, myFile, false);
}
I tested it just with JPG.
--
tomaxxi
http://indisnip.wordpress.com/
Copy link to clipboard
Copied
Hey!
Maybe you can try this code:
var myFile = File('/c/myTest.jpg');
if(app.selection.length > 1){
var myObj = app.activeWindow.activePage.groups.add(app.selection);
myObj.exportFile(ExportFormat.JPG, myFile, false);
myObj.ungroup();
}else{
app.selection[0].exportFile(ExportFormat.JPG, myFile, false);
}
I tested it just with JPG.
--
tomaxxi
http://indisnip.wordpress.com/

Copy link to clipboard
Copied
Awesome! that's exactly what I needed. Thank you so much!
Copy link to clipboard
Copied
You are welcome!
--
tomaxxi
http://indisnip.wordpress.com/

Copy link to clipboard
Copied
One more question. If I have a text frame and a picture frame grouped together, is there an easy way to reference that "group" ?
Copy link to clipboard
Copied
Well, you can get all active groups in document like this:
var myGroups = app.activeDocument.groups;
Maybe you can then loop through every group and check how many elements contains like this:
var myExportGroups = Array();
for(var i = 0; i < myGroups.length; i++){
if(myGroups.allGraphics.length == 1 && myGroups.textFrames.length == 1){
myExportGroups.push(myGroups);
}
}
Now you can loop through myExportGroups and export them if you want.
--
tomaxxi
http://indisnip.wordpress.com/

Copy link to clipboard
Copied
awesome thanks!! That's what I needed.

Copy link to clipboard
Copied
One more...
Are there different jpg rendering options that I can use in my script? (Size, quality, etc?)
Thanks,
Lloyd
Copy link to clipboard
Copied
Hey!
Here is some of 'JPEGExportPreference' properties. Use them like this:
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
Property | Type | Access | Description |
---|---|---|---|
antiAlias | bool | r/w | If true, use anti-aliasing for text and vectors during export. |
embedColorProfile | bool | r/w | True to embed the color profile, false otherwise. |
exportResolution | number (range: 1 - 2400) | r/w | The export resolution expressed as a real number instead of an integer. (Range: 1.0 to 2400.0) |
jpegColorSpace | JpegColorSpaceEnum: JpegColorSpaceEnum.RGB JpegColorSpaceEnum.CMYK JpegColorSpaceEnum.GRAY | r/w | One of RGB, CMYK or Gray |
jpegExportRange | ExportRangeOrAllPages: ExportRangeOrAllPages.EXPORT_RANGE ExportRangeOrAllPages.EXPORT_ALL | r/w | The page range to export. |
jpegQuality | JPEGOptionsQuality: JPEGOptionsQuality.LOW JPEGOptionsQuality.MEDIUM JPEGOptionsQuality.HIGH JPEGOptionsQuality.MAXIMUM | r/w | The compression quality. |
jpegRenderingStyle | JPEGOptionsFormat: JPEGOptionsFormat.BASELINE_ENCODING JPEGOptionsFormat.PROGRESSIVE_ENCODING | r/w | The rendering style. |
simulateOverprint | bool | r/w | If true, simulates the effects of overprinting spot and process colors in the same way they would occur when printing. |
useDocumentBleeds | bool | r/w | If true, uses the document's bleed settings in the exported JPEG. |
--
tomaxxi
http://indisnip.wordpress.com/

Copy link to clipboard
Copied
perfect! Thank you (again)!
Copy link to clipboard
Copied
how would you do this, but name the jpeg with the name of the selected image?

Copy link to clipboard
Copied
I think you should be able to use the "name" property of the image when creating your myFile variable(see first few posts at top):
var myFile = File('/c/myTest.jpg');
could become...
var myFile = File('/c/' + myImage.name);
so when the file exports, it will have the name of the image for the new JPG file name.
Hope this helps!
Copy link to clipboard
Copied
Hm... I think you need something like this:
if(app.selection.length == 1 && app.selection[0].allGraphics.length == 1){
var myFile = File("/c/" + app.selection[0].graphics[0].itemLink.name.match(/.+(?=\.)/) + ".jpg");
app.selection[0].exportFile(ExportFormat.JPG, myFile, false);
}
Hope that helps.
--
tomaxxi
http://indisnip.wordpress.com/
Copy link to clipboard
Copied
Hi,
Have you tried exporting to PDF?
I tried and it exports the page, not just the selection
Copy link to clipboard
Copied
Different export formats behave differently. Take RTF export, for example -- that's a Text-only format. I guess PDF could count as a "page only" format.
I never needed any of them but I do recall there are several solutions to this (such as creating a temporary new document the exact size of your export objects). Search the forum.
Copy link to clipboard
Copied
@Jongware – Yeah. Temporary documents might or might not work well, if one consider baseline grid behaviour, tables that exceed text frames or other gimmicks like drop shadows you cannot catch to keep the bounds of your PDF at a minimum.
To do the bounds right (pdf art box and pdf trim box against pdf media box) you have to cross script with PhotoShop for rendering the whole page to get the bounds of its pixel contents from there. Or (a new idea from Mark, thank you for that!) use an AppleScript to read out the clipboard. Wow. What an idea! I'll give that a try if on a Mac…
Uwe
Copy link to clipboard
Copied
It's a hack but gives me nice crisp sub sections of my pages… It don't like text wrap… but for most basic stuff I want its ok…
Copy link to clipboard
Copied
I tried and it exports the page, not just the selection
That's regular behaviour. No bug.
To exclude all superfluent objects, move them temporarily to a different layer, lock that layer or set its visibility to not visible and export the whole page.
Uwe
Copy link to clipboard
Copied
For me this is as handy as it's method is silly… ( mac only ) Good for emailing snippets/smaller sections of my docs… I cheat and use my OS clipboard… I don't need that if statement just there to make the mac only point…
#target indesign
#targetengine muppet
function clipboardtoPDF() {
app.activate();
if ( app.documents.length == 0 ) { return };
var appleScript, doc, pdfClip, result, sel;
doc = app.activeDocument, sel = doc.selection;
if ( sel.length == 0 ) { return };
app.copy(); // My Clipboard is PDF…
appleScript = '';
appleScript += 'if first item of first item of (clipboard info) = «class PDF » then\r';
appleScript += 'set idPDF to (path to desktop folder as text) & "idclip.pdf"\r';
appleScript += 'try\r';
appleScript += 'set idPDF to (open for access idPDF with write permission)\r';
appleScript += 'set eof idPDF to 0\r';
appleScript += 'write (the clipboard as «class PDF ») to idPDF\r';
appleScript += 'close access idPDF\r';
appleScript += 'return true\r';
appleScript += 'on error\r';
appleScript += 'try\r';
appleScript += 'close access idPDF\r';
appleScript += 'end try\r';
appleScript += 'return false\r';
appleScript += 'end try\r';
appleScript += 'end if\r';
result = app.doScript( appleScript, ScriptLanguage.APPLESCRIPT_LANGUAGE );
if ( result == true ) {
pdfClip = File( '~/Desktop/idclip.pdf' );
pdfClip.execute();
};
};
if ( /Macintosh/i.test( $.os ) ) { clipboardtoPDF(); };
Copy link to clipboard
Copied
@Muppet Mark – I know this thread is quite cold…
Your AppleScript is not working on my Mac.
MacBook Pro, OSX 10.6.8, InDesign CS5.5 v7.5.3 (language German).
It throws an error (roughly translated from my German UI):
German:
JavaScript Fehler!
Fehlernummer -2741
Fehlerzeichenfolge:
Es wurde "","" erwartet, aber ein "Programmkonstante oder "considering"" wurde gefunden.
JavaScript Error!
Error Number -2741
Error Message:
"","" was expected, but a "Constant" or "considering" was found.
Do you know what is happening here?
Uwe
Copy link to clipboard
Copied
@Muppert Mark – I tried to isolate the problem and used a text file with the AppleScript code feeding a doScript(). Problem persists. So I think it has to do with the AppleScript code itself.
See the following ExtendScript that opens a text file with AppleScript code that lies in the same file path (folder) together with the ExtendScript:
var myFile = File(File($.fileName).path + "/" +"ClipBoardToPDF_AppleScript.txt");
if(!myFile.exists){alert(myFile + " File does not exist");exit()};
myFile.open("r");
var myString = myFile.read();
myFile.close();
app.doScript(myString,ScriptLanguage.APPLESCRIPT_LANGUAGE);
//THROWS ERROR:
/*
JavaScript Fehler!
Fehlernummer -2741
Fehlerzeichenfolge:
Es wurde "","" erwartet, aber
ein "Programmkonstante oder "considering"" wurde gefunden.
*/
//Contents of (should be AppleScript):
//ClipBoardToPDF_AppleScript.txt
/*
if first item of first item of (clipboard info) = «class PDF » then
set idPDF to (path to desktop folder as text) & "idclip.pdf"
try
set idPDF to (open for access idPDF with write permission)
set eof idPDF to 0
write (the clipboard as «class PDF ») to idPDF
close access idPDF
return true
on error
try
close access idPDF
end try
return false
end try
end if
*/
Uwe
Copy link to clipboard
Copied
Hello,
Now am facing problem converting to png for only a particular .ai file which has 4 images. only one among them is being converted but the rest were not converting.
Could some one help me with this
Copy link to clipboard
Copied
Hello,
Trying to understand. Are you using a script for this? Examples above are for jpg and pdf export. Dictionary reference for PNG export preferences only shows PNG export range (page range to export can be export range or export all); for page range you would specify the page(s) to export (specify as page number or array of page numbers when PNG export rage is set to export all).
PNG export preferences also includes the ability to set anti alias (true or false), export resolution, PNG color space (RGB or Gray), PNG Quality (low/medium/high/maximum), simulate overprint (true or false), transparent background (true or false), use document bleeds (true or false).
Hope this helps.
Copy link to clipboard
Copied
Hello Hopkins, yes i am using a script to convert to png format.
Copy link to clipboard
Copied
Hi,
what is your version of InDesign?
There was a bug with CC 2018 ( perhaps also with CC 2017.1, cannot remember the details ) that was fixed in CC 2018.1 where file names for the export file with a slash "/" character will enforce the export to do exactly nothing. No file exported, no file written and no error message. That bug affected JPEG and PNG export.
EDIT
Here the hint:
March 2018 (13.1) release of InDesign CC Release Notes
…
Exporting to PNG or JPEG fails if the file name contains a forward slash (/).
…
Regards,
Uwe


-
- 1
- 2