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

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

Explorer ,
Apr 16, 2019 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

TOPICS
Scripting

Views

4.9K

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

Explorer , Apr 17, 2019 Apr 17, 2019

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.exportR

...

Votes

Translate

Translate
Community Expert ,
Apr 16, 2019 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

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

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

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

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

}

}

}

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

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

Copy link to clipboard

Copied

This works like a charm! Thanks! : ) 

 

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

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
Participant ,
Mar 04, 2022 Mar 04, 2022

Copy link to clipboard

Copied

@darrellpones - The lovely script you posted seems to no longer work. Ran into this issue. Any idea how to fix it? Greenshot 2022-03-05 02.14.00.png

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
Explorer ,
Mar 04, 2022 Mar 04, 2022

Copy link to clipboard

Copied

Will check on this when back in the office

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
Explorer ,
Mar 05, 2022 Mar 05, 2022

Copy link to clipboard

Copied

Hi Phillip

 

I just had to run a job here - still working at this end. I did have them stop at one stage for a brieft period when Indesign was unable to exdport jpgs between updates. The text you have your cursor flashing in does have to have a paragraph style applied to it. To Answer an earlier query. The text I am using - the filename - has been data merged into the doc I have not tied 'a photo caption'. Just the image name without the '.jpg' extension.

 

Cheers

Darrell

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
Participant ,
Mar 06, 2022 Mar 06, 2022

Copy link to clipboard

Copied

Well, wow - that's embarrassing. The text does have a paragraphstyle, but it seems I had forgotten that I had to double click/activate the textbox and not just click on it once/select it before running the script. Thanks for your time/reply. Much obliged! : ) 

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
New Here ,
Jul 22, 2022 Jul 22, 2022

Copy link to clipboard

Copied

Hi Darrell, I get the same error message as Phillip above when I click the text box only once. But when I double click the text box and I run the script, it just does nothing. Do you know what I could be doing wrong? I don't do scripting at all sorry but I'm desperate so I dont have to rename 500 jpgs and just want to use a field from my data merge file to name them. I have place this on the artboard, given it a unique paragraph style, and made it non-printing. Is that correct?

 

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
New Here ,
Jul 22, 2022 Jul 22, 2022

Copy link to clipboard

Copied

Still working here. You need to have a flashing text cursor in the text, and the text has to have a unique text style applied to it. For example 'filename export style' (it doesn't have to be a specifc style name). I assume if you have used for example Head 2 style elsewhere on the page the scripr would get confused?

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
Explorer ,
Oct 03, 2023 Oct 03, 2023

Copy link to clipboard

Copied

Hi Guys, does anyone have an idea how I could add a line to this script to export using bleed settings? Would also love to be able to choose a destination. Cheers Darrell. 


Assume it would be an extra line around here
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high;
app.jpegExportPreferences.exportResolution = 72;
app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;

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 ,
Oct 05, 2023 Oct 05, 2023

Copy link to clipboard

Copied

For the bleed you can use the following line

app.jpegExportPreferences.useDocumentBleeds = true

You can look at the possible options at

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#JPEGExportPreference.html

For code related to showing a dialog to choose the destination folder you can check the following discussion

https://community.adobe.com/t5/indesign-discussions/simple-folder-check-javascript/m-p/11459294#M397...

-Manan

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
Explorer ,
Oct 07, 2023 Oct 07, 2023

Copy link to clipboard

Copied

Hi Manan, thanks so much 1 for answering and 2 for giving me directions to where I can learn more. Really appreciate this thanks. The bleed is working fine - when I have time I will do more research re saving and also exporting as spreads which I assume would be ????
app.jpegExportPreferences.exportingSpread = true

 

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
Explorer ,
Oct 27, 2023 Oct 27, 2023

Copy link to clipboard

Copied

The spread code works !!Yay!!

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
New Here ,
Jan 31, 2024 Jan 31, 2024

Copy link to clipboard

Copied

@Manan Joshi @darrellpones Thanks for all your work on this script , it'll work great for us! Any chance you guys know a way to make the exported files case sensitive to what is typed in the text field? 

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
New Here ,
Feb 02, 2024 Feb 02, 2024

Copy link to clipboard

Copied

NVM i'm dumb lol - i just deleted the part where it says ".toLowerCase()" and now its working perfectly 

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
New Here ,
Feb 02, 2024 Feb 02, 2024

Copy link to clipboard

Copied

@darrellpones @Manan Joshi 
Okay new issue, is there a way i can get this to pick up on the paragraph style if it's on the master page rather than a regular page? 

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
Explorer ,
Feb 02, 2024 Feb 02, 2024

Copy link to clipboard

Copied

You want to export the master pages?

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
Explorer ,
Feb 02, 2024 Feb 02, 2024

Copy link to clipboard

Copied

That was clever, I am not much of a scripter myself. I found the script originally and it has grown through the comments on this page. 

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
New Here ,
Feb 02, 2024 Feb 02, 2024

Copy link to clipboard

Copied

thanks for the reply! Basically I'm wanting to build a template with every possible file size that we use (currently 70+) and have them each saved as a master page with all the text boxes pre-typed and ready to go. If you use the master pages, the text box is always there and you cant mess them up. I've attached some screenshots to help make sense lol - ideally we'd open the template,  pull down whatever few pages that the current project needs, use "find/replace" to switch date_projectname, and then everything is named perfectly on export. 

The problem is the script doesn't see the text box if its on the master page. Right now, it only works if you pull down a page, then cut the text box off of the master page, and paste it onto the working page. Was hoping that I could just leave it on the master page and add some code to fix the export lol hope that makes sense. Maybe someone will see this and have an easy fix (this stuff is wayyy over my head lol) 

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
Explorer ,
Feb 02, 2024 Feb 02, 2024

Copy link to clipboard

Copied

The only thing I can think of is a work around. Get your doc ready / Save it / Selct all the pages in the pages palette /  right mouse click / select overide all master page items / this will then bring the text blocks onto the relevant pages / export as normal / close without saving ??? would that do it? Its not ideal

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