Highlighted

Export pages to jpg with individual filenames (from photo caption in slug)

Explorer ,
Apr 16, 2019

Copy link to clipboard

Copied

Hi Guys

I am wanting to export multiple pages of a INDD file to JPG and name the files based on a caption generated from the image on each page. (the caption appears in the slug area. Previously we have been doing this manually. We do Team and Portrait Photography, there is the option to use 'Sports Photo Automation' but this would leave me with much larger file sizes. I have seen a couple of posts relating to this but they don't seem to be specific enough and i am no scripter.

Thanks for any advice, apologies if this has been answered before.

Sample.jpg

if (app.documents.length != 0){

var myDoc = app.activeDocument;

MakeJPEGfile();

} else {

alert("Please open a document and try again.");

}

function myPS() {

try {

return myDoc.selection[0].appliedParagraphStyle;

} catch (e) {

alert("Place cursor to text with paragraph style for filenames");

exit();

}

}

function MakeJPEGfile() {

app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high;

app.jpegExportPreferences.exportResolution = 72;

app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;

app.findGrepPreferences = null;

app.findGrepPreferences.appliedParagraphStyle = myPS();

var f = myDoc.findGrep();

for (var myCounter = 0; myCounter < f.length; myCounter++) {

try {

var curPage = f[myCounter].parentTextFrames[0].parentPage;

if (curPage.appliedSection.name != "") {

curPage.appliedSection.name = "";

}

var objName = f[myCounter].contents.replace(/ /g,"_").toLowerCase();

app.jpegExportPreferences.pageString = curPage.name;

//var myFilePath = "~/C:\output/" + myPageName + ".jpg";

var myFilePath = myDoc.filePath + "/" + objName + ".jpg"; //export to a folder of the current document

var myFile = new File(myFilePath);

myDoc.exportFile(ExportFormat.jpg, myFile, false);

} catch(e) {

//pasteboard?

}

}

}

TOPICS
Scripting

Views

1.0K

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

Export pages to jpg with individual filenames (from photo caption in slug)

Explorer ,
Apr 16, 2019

Copy link to clipboard

Copied

Hi Guys

I am wanting to export multiple pages of a INDD file to JPG and name the files based on a caption generated from the image on each page. (the caption appears in the slug area. Previously we have been doing this manually. We do Team and Portrait Photography, there is the option to use 'Sports Photo Automation' but this would leave me with much larger file sizes. I have seen a couple of posts relating to this but they don't seem to be specific enough and i am no scripter.

Thanks for any advice, apologies if this has been answered before.

Sample.jpg

if (app.documents.length != 0){

var myDoc = app.activeDocument;

MakeJPEGfile();

} else {

alert("Please open a document and try again.");

}

function myPS() {

try {

return myDoc.selection[0].appliedParagraphStyle;

} catch (e) {

alert("Place cursor to text with paragraph style for filenames");

exit();

}

}

function MakeJPEGfile() {

app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high;

app.jpegExportPreferences.exportResolution = 72;

app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;

app.findGrepPreferences = null;

app.findGrepPreferences.appliedParagraphStyle = myPS();

var f = myDoc.findGrep();

for (var myCounter = 0; myCounter < f.length; myCounter++) {

try {

var curPage = f[myCounter].parentTextFrames[0].parentPage;

if (curPage.appliedSection.name != "") {

curPage.appliedSection.name = "";

}

var objName = f[myCounter].contents.replace(/ /g,"_").toLowerCase();

app.jpegExportPreferences.pageString = curPage.name;

//var myFilePath = "~/C:\output/" + myPageName + ".jpg";

var myFilePath = myDoc.filePath + "/" + objName + ".jpg"; //export to a folder of the current document

var myFile = new File(myFilePath);

myDoc.exportFile(ExportFormat.jpg, myFile, false);

} catch(e) {

//pasteboard?

}

}

}

TOPICS
Scripting

Views

1.0K

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
Apr 16, 2019 0
Adobe Community Professional ,
Apr 16, 2019

Copy link to clipboard

Copied

Hi Darrell,

How are the captions generated for the image, is there only a single image on a page?

-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...
Apr 16, 2019 0
Adobe Community Professional ,
Apr 17, 2019

Copy link to clipboard

Copied

Hi Darrell,

if the caption is made with InDesign's Caption function it might be that the image's container frame is grouped with the text frame that holds the caption text.

To get the group you could access the allGraphics array of a page or you could follow a specific link in the Links collection and climb the parent tree until you find a group. Then check for the contents of a text frame that is part of the group.

Regards,
Uwe

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...
Apr 17, 2019 0
Explorer ,
Apr 17, 2019

Copy link to clipboard

Copied

Hi Guys

Thansk for your consideration

I found a script here

https://indesignsecrets.com/topic/export-pages-to-jpg-with-custom-filenames

The PNG script works fine (doesn't name files though) but the JPG one seems to work (as it takes time to run) but I can't find the output?

My Captions are not grouped to the image, I will make the text style colour transparent once its up and running correctly

Its a 60 poage document but I will have to do thousands of these over the year so want to streamline the process as much as possible

Sample.jpg

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...
Apr 17, 2019 0
Explorer ,
Apr 17, 2019

Copy link to clipboard

Copied

This script seems to run when I use the original destination and I cant find the files. When I use the commented out line with a destination of c:\output it doesn't run. I am new to this can anyone advise me of the correct syntax to chose a destination?

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...
Apr 17, 2019 0
Explorer ,
Apr 17, 2019

Copy link to clipboard

Copied

if (app.documents.length != 0){

var myDoc = app.activeDocument;

MakeJPEGfile();

} else {

alert("Please open a document and try again.");

}

function myPS() {

try {

return myDoc.selection[0].appliedParagraphStyle;

} catch (e) {

alert("Place cursor to text with paragraph style for filenames");

exit();

}

}

function MakeJPEGfile() {

app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high;

app.jpegExportPreferences.exportResolution = 72;

app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;

app.findGrepPreferences = null;

app.findGrepPreferences.appliedParagraphStyle = myPS();

var f = myDoc.findGrep();

for (var myCounter = 0; myCounter < f.length; myCounter++) {

try {

var curPage = f[myCounter].parentTextFrames[0].parentPage;

if (curPage.appliedSection.name != "") {

curPage.appliedSection.name = "";

}

var objName = f[myCounter].contents.replace(/ /g,"_").toLowerCase();

app.jpegExportPreferences.pageString = curPage.name;

//var myFilePath = "~/C:\output/" + myPageName + ".jpg";

var myFilePath = myDoc.filePath + "/" + objName + ".jpg"; //export to a folder of the current document

var myFile = new File(myFilePath);

myDoc.exportFile(ExportFormat.jpg, myFile, false);

} catch(e) {

//pasteboard?

}

}

}

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...
Apr 17, 2019 1
Explorer ,
Apr 17, 2019

Copy link to clipboard

Copied

This has finally started working, it may have something to do with a non printing layer. At least the files are now appearing ton the same destination as the indesign file. any hints on redirecting would be great

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...
Apr 17, 2019 0
Explorer ,
May 29, 2020

Copy link to clipboard

Copied

This works like a charm! Thanks! : ) 

 

Now if it only if it could export PDFs ... : )

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...
May 29, 2020 0