Reply To: Export pages to jpg with custom filenames

#64231
Eugenyus
Member

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 = 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?
}
}

This article was last modified on February 21, 2013

Comments (0)

Loading comments...