Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

indesign script - export selected objects as JPGs - adding extra unwanted padding

Community Beginner ,
Nov 24, 2025 Nov 24, 2025

hello all - wondering if i can get some help with a script.

 

script function - export all and only the selected objects on a page as individual JPGs. 

 

issue - the JPGs keep exporting with extra padding at the top of the box IF there is text close to the top edge. nothing is exceeding the background (example text frame boxes etc) - everything is inside of the grouped background. it is also only happening if there is text next to a top edge - any other edge it does not add any extra padding, hopefully this screenshot will help explain

melissasones_0-1764044166203.png

 

the script:

 

(function () {
if (app.documents.length === 0) { alert("Open a document first."); return; }

var doc = app.activeDocument;
if (!doc.selection || doc.selection.length === 0) {
alert("Select the items you want to export, then run the script.");
return;
}

var items = [];
for (var i = 0; i < doc.selection.length; i++) {
var it = doc.selection[i];
if (it.hasOwnProperty("geometricBounds")) items.push(it);
}
if (items.length === 0) { alert("Nothing exportable in the selection."); return; }

items.sort(function(a, b) {
var A = a.geometricBounds, B = b.geometricBounds;
var rowTolerance = 10;
if (Math.abs(A[0] - B[0]) > rowTolerance) {
return A[0] - B[0];
} else {
return A[1] - B[1];
}
});

var outFolder = new Folder('~/Desktop/Export');
if (!outFolder.exists) outFolder.create();

app.jpegExportPreferences.exportResolution = 144;
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;

var prefix = "FileName_Export-";
function pad2(n){ n = String(n); return n.length < 2 ? "0" + n : n; }

for (var j = 0; j < items.length; j++) {
var filename = prefix + pad2(j + 1) + ".jpg";
var outFile = new File(outFolder.fsName + "/" + filename);
try {
items[j].exportFile(ExportFormat.JPG, outFile, false);
} catch (e) {
$.writeln("Failed to export selected item #" + (j+1) + ": " + e);
}
}

alert("Done! Saved to " + outFolder.fsName);
})();

 

 

----

thank you,

melissa

 

TOPICS
Scripting
256
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Nov 25, 2025 Nov 25, 2025

Thanks for this Manan. Exporting as a single selection was doing the same thing, a quick google and someone had suggested trying exporting out of an IDML file and that has fixed the issue. 

Translate
Community Expert ,
Nov 25, 2025 Nov 25, 2025

Hi @melissa.sones,

The first thing I would check if I were you was to see if I am able to make it work manually. Only after that would spending time on fixing the script be worth it.

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 25, 2025 Nov 25, 2025

Thanks for this Manan. Exporting as a single selection was doing the same thing, a quick google and someone had suggested trying exporting out of an IDML file and that has fixed the issue. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 25, 2025 Nov 25, 2025
LATEST

That is great news @melissa.sones. Over multiple saves the indd files gathers up some corruptions, exporting out to IDML clears out all this. So, if there is something that does not make sense it is a trick worth trying.

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines