Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

exportFile() - export selection option via script?

Guest
Aug 09, 2010 Aug 09, 2010

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

TOPICS
Scripting
22.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advisor , Aug 09, 2010 Aug 09, 2010

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/

Translate
Advisor ,
Aug 09, 2010 Aug 09, 2010

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/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 09, 2010 Aug 09, 2010

Awesome! that's exactly what I needed. Thank you so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 09, 2010 Aug 09, 2010

You are welcome!

--

tomaxxi

http://indisnip.wordpress.com/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 09, 2010 Aug 09, 2010

One more question. If I have a text frame and a picture frame grouped together, is there an easy way to reference that "group" ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 09, 2010 Aug 09, 2010

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/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 10, 2010 Aug 10, 2010

awesome thanks!! That's what I needed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 10, 2010 Aug 10, 2010

One more...

Are there different jpg rendering options that I can use in my script?  (Size, quality, etc?)

Thanks,

Lloyd

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 10, 2010 Aug 10, 2010

Hey!

Here is some of 'JPEGExportPreference' properties. Use them like this:

app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;

Property

Type Access Description
antiAliasboolr/wIf true, use anti-aliasing for text and vectors during export.
embedColorProfileboolr/wTrue to embed the color profile, false otherwise.
exportResolutionnumber (range: 1 - 2400)r/wThe export resolution expressed as a real number instead of an integer.  (Range: 1.0 to 2400.0)
jpegColorSpaceJpegColorSpaceEnum:
JpegColorSpaceEnum.RGB
JpegColorSpaceEnum.CMYK
JpegColorSpaceEnum.GRAY
r/wOne of RGB, CMYK or Gray
jpegExportRangeExportRangeOrAllPages:
ExportRangeOrAllPages.EXPORT_RANGE
ExportRangeOrAllPages.EXPORT_ALL
r/wThe page range to export.
jpegQualityJPEGOptionsQuality:
JPEGOptionsQuality.LOW
JPEGOptionsQuality.MEDIUM
JPEGOptionsQuality.HIGH
JPEGOptionsQuality.MAXIMUM
r/wThe compression quality.
jpegRenderingStyleJPEGOptionsFormat:
JPEGOptionsFormat.BASELINE_ENCODING
JPEGOptionsFormat.PROGRESSIVE_ENCODING
r/wThe rendering style.
simulateOverprintboolr/wIf true, simulates the effects of overprinting spot and process colors in  the same way they would occur when printing.
useDocumentBleedsboolr/wIf true, uses the document's bleed settings in the exported JPEG.

--

tomaxxi

http://indisnip.wordpress.com/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 12, 2010 Aug 12, 2010

perfect! Thank you (again)!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 01, 2010 Oct 01, 2010

how would you do this, but name the jpeg with the name of the selected image?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 01, 2010 Oct 01, 2010

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Oct 01, 2010 Oct 01, 2010

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/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 23, 2012 Mar 23, 2012

Hi,

Have you tried exporting to PDF?

I tried and it exports the page, not just the selection

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 23, 2012 Mar 23, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2012 Mar 24, 2012

@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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 24, 2012 Mar 24, 2012

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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 24, 2012 Mar 24, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Mar 24, 2012 Mar 24, 2012

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(); };

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 14, 2014 Feb 14, 2014

@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.

ERROR-2741.png

Do you know what is happening here?

Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 14, 2014 Feb 14, 2014

@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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 25, 2018 Apr 25, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 25, 2018 Apr 25, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 25, 2018 Apr 25, 2018

Hello Hopkins, yes i am using a script to convert to png format.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2018 Apr 25, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines