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

Export images to folders

Explorer ,
Dec 21, 2020 Dec 21, 2020

Copy link to clipboard

Copied

Hi there,

     I need to to export images from a 100 page Indesign catalogue.

I need the images from page 1 to be exported in folder 001, from page 2 to folder 002, from page 3 to folder 003  etc. upto all pages to their format (just a copy of them).

Any script that do the job ?

Could you help me please?

Thanks is advance.

TOPICS
Scripting

Views

418

Translate

Translate

Report

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

Contributor , Dec 21, 2020 Dec 21, 2020

Hi,

this script will create a folder "exported_images" in the same folder where your Indesign file is saved. The images then will be copied into the subfolders "001", "002", ...

#targetengine "imageExporter"

var mydoc = app.activeDocument;
var pages = mydoc.pages;
var allGraphics = null;
var mainFolder_String = decodeURI(mydoc.filePath + "/exported_images");
var mainFolder_Folder = new Folder(mainFolder_String);
var pageFolder = null;
var folderNumber = "";

if(!mainFolder_Folder.exists){
	mainFo
...

Votes

Translate

Translate
Contributor ,
Dec 21, 2020 Dec 21, 2020

Copy link to clipboard

Copied

Hi,

this script will create a folder "exported_images" in the same folder where your Indesign file is saved. The images then will be copied into the subfolders "001", "002", ...

#targetengine "imageExporter"

var mydoc = app.activeDocument;
var pages = mydoc.pages;
var allGraphics = null;
var mainFolder_String = decodeURI(mydoc.filePath + "/exported_images");
var mainFolder_Folder = new Folder(mainFolder_String);
var pageFolder = null;
var folderNumber = "";

if(!mainFolder_Folder.exists){
	mainFolder_Folder.create();
}

var progressbar = pbar();
progressbar.show();
progressbar.prog.maxvalue = pages.length;

for(var p = 0; p < pages.length; p++){
	progressbar.prog.value = p;
	progressbar.update();
	
	if(p +1 >= 100){
		folderNumber = p + 1;
	} else if (p +1 >= 10){
		folderNumber = "0" + (p + 1);
	} else {
		folderNumber = "00" + (p +1);
	}
	
	pageFolder = new Folder(mainFolder_String + "/" + folderNumber);
	
	if(!pageFolder.exists){
		pageFolder.create();
	}
	
	allGraphics = pages[p].allGraphics;
	
	for(var g = 0; g < allGraphics.length; g++){
		
		var currentGraphic = new File(decodeURI(allGraphics[g].itemLink.filePath));
		
		currentGraphic.copy(mainFolder_String + "/" + folderNumber + "/" + allGraphics[g].itemLink.name);
	}
}

progressbar.close();
alert("Image export completed");

function pbar(){
	var w = Window.find("palette", "progress");
	if(w != null){
		return w;
	}
	
	w = new Window("palette", "progress");
	w.prog = w.add("progressbar", undefined, 0, 100);
	w.prog.preferredSize.width = 200;
	
	return w;
}

 

Votes

Translate

Translate

Report

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 ,
Dec 22, 2020 Dec 22, 2020

Copy link to clipboard

Copied

Hi crazyPanda,

note: One should always test if a graphic has an itemLink at all; images could be pasted to the layout through the clipboard.

And of course property status of itemLink should show LinkStatus.NORMAL.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

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
Contributor ,
Dec 23, 2020 Dec 23, 2020

Copy link to clipboard

Copied

LATEST

Hi Uwe,

thanks for the heads-up. I guess I will handle these issues in the easiest and laziest way by using try{} catch().

 

Another issue may occur when there are two different images on the same page that are linked from different sources but have the same name, e.g. c:\image_001.jpg, e:\image_001.jpg. In this case there would only be one "image_001.jpg" at the end because the other one got overwritten. But for the moment I will assume that this is not the case and ignore it for now.

 

#targetengine "imageExporter"

var mydoc = app.activeDocument;
var pages = mydoc.pages;
var allGraphics = null;
var mainFolder_String = decodeURI(mydoc.filePath + "/exported_images");
var mainFolder_Folder = new Folder(mainFolder_String);
var pageFolder = null;
var folderNumber = "";

if(!mainFolder_Folder.exists){
	mainFolder_Folder.create();
}

var progressbar = pbar();
progressbar.show();
progressbar.prog.maxvalue = pages.length;

for(var p = 0; p < pages.length; p++){
	progressbar.prog.value = p;
	progressbar.update();
	
	if(p +1 >= 100){
		folderNumber = p + 1;
	} else if (p +1 >= 10){
		folderNumber = "0" + (p + 1);
	} else {
		folderNumber = "00" + (p +1);
	}
	
	pageFolder = new Folder(mainFolder_String + "/" + folderNumber);
	
	if(!pageFolder.exists){
		pageFolder.create();
	}
	
	allGraphics = pages[p].allGraphics;
	
	for(var g = 0; g < allGraphics.length; g++){
		try {
			var currentGraphic = new File(decodeURI(allGraphics[g].itemLink.filePath));
			
			currentGraphic.copy(mainFolder_String + "/" + folderNumber + "/" + allGraphics[g].itemLink.name);	
		} catch (err) {
			
		}
	}
}

progressbar.close();
alert("Image export completed");

function pbar(){
	var w = Window.find("palette", "progress");
	if(w != null){
		return w;
	}
	
	w = new Window("palette", "progress");
	w.prog = w.add("progressbar", undefined, 0, 100);
	w.prog.preferredSize.width = 200;
	
	return w;
}

 

Votes

Translate

Translate

Report

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