0

I'm using the following script to export all items / per page from an indesign document to jpg. This script also crops all items to their size given by the container in indesign.

I would like to limit this script to export only all "placed images", because I only need the images. At the moment I get also all rectangular objects like text boxes and so on.

#target InDesign 

//set properties for export to your needs
 with(app.jpegExportPreferences){ 
    antiAlias = true; 
embedColorProfile = false; 
exportResolution = 300; 
jpegColorSpace = JpegColorSpaceEnum.RGB; //JpegColorSpaceEnum.CMYK, JpegColorSpaceEnum.GRAY     r/w    One of RGB, CMYK or Gray 
jpegQuality = JPEGOptionsQuality.HIGH; //JPEGOptionsQuality.LOW, JPEGOptionsQuality.MEDIUM, JPEGOptionsQuality.HIGH, JPEGOptionsQuality.MAXIMUM     r/w    The compression quality. 
jpegRenderingStyle = JPEGOptionsFormat.BASELINE_ENCODING; // JPEGOptionsFormat.PROGRESSIVE_ENCODING     r/w    The rendering style. 
simulateOverprint = true; 
} 

 //doc has to be saved once
var theDoc = app.activeDocument; 
var docName = theDoc.name; 
var docShortName = docName.replace(/.indd/, '') 
var docPath = '' + theDoc.fullName; 
var docContainerPath = docPath.replace(docName, '') 
var destPath = docContainerPath + '/' + docShortName + '_jpgExport/' 
if(Folder(destPath).create() != true){alert('Could not create targetfolder.'); exit();} 

var pageItems = theDoc.pageItems.everyItem().getElements(); 

l = pageItems.length; 
counter = 0;
for(var i = 0; i < l; i++){
    counter = counter + 1;
    var singlePageItem = pageItems[i];
    currParentPage = singlePageItem.parentPage;
if(currParentPage == null){parentPageNumber = 'pasteboard'}else{parentPageNumber = singlePageItem.parentPage.name; }

newFile =new File(destPath + 'page_' +  parentPageNumber + '_' + 'item_' + counter + '.jpg'); 

if(singlePageItem.exportFile(ExportFormat.JPG,  newFile) === false){alert(newFile + ' could not write jpg-File.')}  
        }
emjay
  • 1,491
  • 5
  • 17
  • 35
  • Maybe the answer of this question will help to get the answer: http://stackoverflow.com/questions/10983501/indesign-cs6-scripting-exporting-images/12819043#12819043 But I don't know how to use and integrate this into the script. – emjay Jun 20 '14 at 10:48

1 Answers1

1

If I understand you correctly, in place of:

var pageItems = theDoc.pageItems.everyItem().getElements();

you could use:

var pageItems = theDoc.allGraphics;

which would grab all the graphic elements instead of every pageItem. Is this what you were thinking?

EDIT: You may need to grab the parent element of every graphic element in order to export them.

Josh Voigts
  • 4,114
  • 1
  • 18
  • 43
  • Cannot test, but I believe you have to refer to the **parent** of a 'raw' graphic -- its containing frame. That would be `var singlePageItem = graphicItems[i].parent;` then. – Jongware Jun 25 '14 at 17:28
  • So it should be `theDoc.graphics.everyItem().parent`? – Josh Voigts Jun 25 '14 at 17:39
  • Something like that, yes. Probably `graphicItems = theDoc.allGraphics.everyItem().parent.getElements();`, in full -- [Document](http://jongware.mit.edu/idcs6js/pc_Document.html) doesn't have a `graphics`. – Jongware Jun 25 '14 at 17:42