Reply To: Export pages to jpg with custom filenames

#91104
David Savini
Member

Hello, if you still looking for a png version, this one is workiing :

if (app.documents.length != 0){
var myDoc = app.activeDocument;
MakePNGfile();
} 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 MakePNGfile() {

app.pngExportPreferences.pngQuality = PNGQualityEnum.MAXIMUM;
app.pngExportPreferences.exportResolution = 72;
app.pngExportPreferences.transparentBackground = true;
app.pngExportPreferences.pngExportRange = PNGExportRangeEnum.EXPORT_RANGE;

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.pngExportPreferences.pageString = curPage.name;
var myFilePath = myDoc.filePath + “/” + objName + “.png”; //export to a folder of the current document
var myFile = new File(myFilePath);
myDoc.exportFile(ExportFormat.PNG_FORMAT, myFile, false);
} catch(e) {
//pasteboard?
}
}
}

This article was last modified on January 10, 2017

Comments (0)

Loading comments...