Reply To: Export pages to jpg with custom filenames

#72624

Hi,
Thanks for the posts above, I am a novice in creating scripts and am trying to amend the script so that I can use it to export the files as pngs rather than jpegs. Below is the script I have so far, but it doesn’t seem to save any files. I don’t get an error message however. Any ideas?
Thanks very much in advance!

if (app.documents.length != 0){
var myDoc = app.activeDocument;
MakePNG_FORMATfile();
} 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 MakePNG_FORMATfile() {
app.pngExportPreferences.pngQuality = PNGQualityEnum.MAXIMUM;
app.pngExportPreferences.exportResolution = 72;
app.pngExportPreferences.pngExportRange = 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.png_formatExportPreferences.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, myFile, false);
} catch(e) {
//pasteboard?
}
}
}

This article was last modified on January 12, 2015

Comments (0)

Loading comments...