Question
Error When Exporting Artboards as JPG Using Script
if (exportArtboards) {
var baseFileName = doc.name.replace(/\.[^\.]+$/, '');
var fileFolder = doc.path;
for (var n = 0; n < doc.artboards.length; n++) {
doc.artboards.setActiveArtboardIndex(n);
var artboardBounds = doc.artboards[n].artboardRect;
var artboardWidth = artboardBounds[2] - artboardBounds[0];
var artboardHeight = artboardBounds[1] - artboardBounds[3];
var targetWidth = 1280;
var targetHeight = Math.round((artboardHeight / artboardWidth) * targetWidth);
var fileName = (doc.artboards.length === 1 ? baseFileName : baseFileName + (n + 1)) + ".jpg";
var exportFile = new File(fileFolder + "/" + fileName);
var exportOptions = new ExportOptionsJPEG();
exportOptions.qualitySetting = 60;
exportOptions.artBoardClipping = true;
exportOptions.horizontalScale = (targetWidth / artboardWidth) * 100;
exportOptions.verticalScale = (targetHeight / artboardHeight) * 100;
$.writeln("Artboard bounds: " + artboardBounds);
$.writeln("Original width: " + artboardWidth + ", height: " + artboardHeight);
$.writeln("Export target width: " + targetWidth + ", height: " + targetHeight);
$.writeln("Horizontal scale: " + exportOptions.horizontalScale + ", Vertical scale: " + exportOptions.verticalScale);
doc.exportFile(exportFile, ExportType.JPEG, exportOptions);
}
}I used the script above to export artboards as JPG images. The problem now is that if the artboard size is too small, an error message appears: 'Specified value greater than maximum allowed value.' After checking the documentation, I found that this error occurs if the scale factor is greater than 7.76. Is there any way to solve this?
