Highlighted

Exporting separate pages and saving filenames as placed image filename

New Here ,
May 19, 2020

Copy link to clipboard

Copied

Hello. Shot in the dark here. Is there a way to export pages into separate images (.png or .jpeg) with each separate file automatically being named as the filename of the placed image? I've got large books being created, about 10k-20k pages total, that needs each page separated and saved with the filename of the placed image on each page. I don't think there is a solution. If y'all have any advice on how to make this a quicker process, even if it's not in inDesign, that'd be appreciated. Trying to save myself and coworkers time of retyping filenames. Thanks!

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

Try the following code

var doc = app.documents[0]
for(var i = 0; i < doc.pages.length; i++)
{
	var p = doc.pages[i].allGraphics
	if(p != 0)
	{
		var imgName = p[0].itemLink.name.replace(/\..*/, "")
		exportJpeg(doc.pages[i].name,imgName)
	}
}

function exportJpeg(pageNumber, imgName)
{
	app.jpegExportPreferences.properties = 
	{
	   antiAlias: true,
	   embedColorProfile: true,
	   exportResolution: 150,
	   jpegColorSpace: JpegColorSpaceEnum.rgb,
	   jpegExportRange: ExportRangeOrAllPages.exportRange,
	   jpegQuality: JPEGOptionsQuality.maximum,
	   jpegRenderingStyle: JPEGOptionsFormat.baselineEncoding,
	   useDocumentBleeds: false,
	   simulateOverprint: false,
	   pageString: pageNumber
	}
	var tempFile = File("~/Desktop/" + imgName + ".jpg");
	doc.exportFile(ExportFormat.jpg, tempFile);
}

It will save the jpegs on the desktop, and if the page has more than 1 image placed it will pick the first one

 

-Manan

Topics

How to, Import and export

Views

329

Likes

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

Exporting separate pages and saving filenames as placed image filename

New Here ,
May 19, 2020

Copy link to clipboard

Copied

Hello. Shot in the dark here. Is there a way to export pages into separate images (.png or .jpeg) with each separate file automatically being named as the filename of the placed image? I've got large books being created, about 10k-20k pages total, that needs each page separated and saved with the filename of the placed image on each page. I don't think there is a solution. If y'all have any advice on how to make this a quicker process, even if it's not in inDesign, that'd be appreciated. Trying to save myself and coworkers time of retyping filenames. Thanks!

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

Try the following code

var doc = app.documents[0]
for(var i = 0; i < doc.pages.length; i++)
{
	var p = doc.pages[i].allGraphics
	if(p != 0)
	{
		var imgName = p[0].itemLink.name.replace(/\..*/, "")
		exportJpeg(doc.pages[i].name,imgName)
	}
}

function exportJpeg(pageNumber, imgName)
{
	app.jpegExportPreferences.properties = 
	{
	   antiAlias: true,
	   embedColorProfile: true,
	   exportResolution: 150,
	   jpegColorSpace: JpegColorSpaceEnum.rgb,
	   jpegExportRange: ExportRangeOrAllPages.exportRange,
	   jpegQuality: JPEGOptionsQuality.maximum,
	   jpegRenderingStyle: JPEGOptionsFormat.baselineEncoding,
	   useDocumentBleeds: false,
	   simulateOverprint: false,
	   pageString: pageNumber
	}
	var tempFile = File("~/Desktop/" + imgName + ".jpg");
	doc.exportFile(ExportFormat.jpg, tempFile);
}

It will save the jpegs on the desktop, and if the page has more than 1 image placed it will pick the first one

 

-Manan

Topics

How to, Import and export

Views

330

Likes

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
Adobe Community Professional ,
May 19, 2020

Copy link to clipboard

Copied

Try the following code

var doc = app.documents[0]
for(var i = 0; i < doc.pages.length; i++)
{
	var p = doc.pages[i].allGraphics
	if(p != 0)
	{
		var imgName = p[0].itemLink.name.replace(/\..*/, "")
		exportJpeg(doc.pages[i].name,imgName)
	}
}

function exportJpeg(pageNumber, imgName)
{
	app.jpegExportPreferences.properties = 
	{
	   antiAlias: true,
	   embedColorProfile: true,
	   exportResolution: 150,
	   jpegColorSpace: JpegColorSpaceEnum.rgb,
	   jpegExportRange: ExportRangeOrAllPages.exportRange,
	   jpegQuality: JPEGOptionsQuality.maximum,
	   jpegRenderingStyle: JPEGOptionsFormat.baselineEncoding,
	   useDocumentBleeds: false,
	   simulateOverprint: false,
	   pageString: pageNumber
	}
	var tempFile = File("~/Desktop/" + imgName + ".jpg");
	doc.exportFile(ExportFormat.jpg, tempFile);
}

It will save the jpegs on the desktop, and if the page has more than 1 image placed it will pick the first one

 

-Manan

Likes

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
Reply
Loading...
New Here ,
May 19, 2020

Copy link to clipboard

Copied

Thank you! I'll have my team give it a go. Greatly appreciate your quick feedback and reply.

Likes

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
Reply
Loading...
New Here ,
May 22, 2020

Copy link to clipboard

Copied

Thank you! This code works. Could you advise on what I need to edit in the code to change from the image name to a word in a text box? Should I only change imgName to txtName?

Likes

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
Reply
Loading...
Adobe Community Professional ,
May 22, 2020

Copy link to clipboard

Copied

Yes you guessed it right that imgName is the variable used for creating the name of the file. But i am not sure what is txtName. I hope you have code to get the value for txtName variable. Also make sure you just change the imgName in this line

var imgName = p[0].itemLink.name.replace(/\..*/, "")

All other reference of imgName use the value set in this statement

 

-Manan

Likes

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
Reply
Loading...
New Here ,
May 25, 2020

Copy link to clipboard

Copied

My apologies. For txtName, I meant that the filename would be saved as the word(s) from the text box instead of the image.

Likes

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
Reply
Loading...