Copy link to clipboard
Copied
I have an existing script that exports jpegs. I am wondering if it is possible to add some lines to it so that it exports with the suffix 'Page size' and then 'px'. Any help with this would be greatly appreciated, thanks.
------------------------------------------
var doc = app.activeDocument;
var myFolder = doc.filePath;
var jpg_name = doc.name.replace(/.indd$/i, “”);
for(var p = 0; p < app.documents[0].pages.length; p++) {
var myPageName = doc.pages[p].name;
// Set JPEG export preferences
app.jpegExportPreferences.properties = {
antiAlias: true,
embedColorProfile: true,
exportResolution: 72,
// exportingSpread: true, // Uncomment if spreads
jpegColorSpace: JpegColorSpaceEnum.rgb,
jpegExportRange: ExportRangeOrAllPages.exportRange,
jpegQuality: JPEGOptionsQuality.maximum,
jpegRenderingStyle: JPEGOptionsFormat.baselineEncoding,
useDocumentBleeds: false,
simulateOverprint: false,
pageString: myPageName,
}
doc.exportFile(ExportFormat.jpg, File(myFolder +”/”+ jpg_name +” “+myPageName+ “.jpg”), false);
}
alert(“Done Exporting jpg’s!”);
Copy link to clipboard
Copied
Replace the line beginning with
doc.exportFile(...with these lines:
var oldUnits = [
doc.viewPreferences.horizontalMeasurementUnits,
doc.viewPreferences.verticalMeasurementUnits
];
doc.viewPreferences.horizontalMeasurementUnits = doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.PIXELS;
doc.exportFile(ExportFormat.jpg, File(
myFolder + "/" + jpg_name + " " + myPageName + " " +
doc.documentPreferences.pageWidth + " x " +
doc.documentPreferences.pageHeight + "px.jpg"
), false);
doc.viewPreferences.horizontalMeasurementUnits = oldUnits[0];
doc.viewPreferences.verticalMeasurementUnits = oldUnits[1];
The result of the exported file looks like this:
MyDocument PageName 1920 x 1080px.jpg
Copy link to clipboard
Copied
Thanks very much for your response. It looks promising but when I tested it on a page size of 500x400px but it gave me this result. Wonder if it's an issue with how I've set up the file, but it's under web and pixels as the unit of measure so not sure.
"untitled 1 209.999999999936 x 296.999999999461px"
Copy link to clipboard
Copied
Replace these two lines
doc.documentPreferences.pageWidth + " x " +
doc.documentPreferences.pageHeight + "px.jpg"with these lines:
Math.round(doc.documentPreferences.pageWidth) + " x " +
Math.round(doc.documentPreferences.pageHeight) + "px.jpg"
Copy link to clipboard
Copied
Thanks, that just made it a whole number, but I realised that it wasn't giving it in pixels but in millimeters for some reason, even though the units were being set to pixels.
Instead of having "pageWidth + pageHeight", changing it to "pageSize" fixed it.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more