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!
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.expor
...
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
Copy link to clipboard
Copied
Thank you! I'll have my team give it a go. Greatly appreciate your quick feedback and reply.
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?
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
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.