Okay, let's create that ExtendScript for InDesign and discuss the best starting size.
Understanding the Goal:
The script will take your currently open InDesign document (the template), duplicate it for each specified Google Banner size, resize the page to the target dimensions, and proportionally scale all content on the first page to fit the new size, ensuring text scales along with graphics.
Best Starting Size Recommendation:
There's no single "perfect" size, but a good strategy is to start with one of the larger, more common formats. This generally makes scaling down easier and maintains better quality, especially if you have raster images (though InDesign handles vector and text scaling well).
Good options for your master template size:
- 728 x 90 (Leaderboard): A very common large horizontal format. Good if your core design is fundamentally wide.
- 300 x 600 (Half Page): A large vertical format. Good if your design is fundamentally tall.
- 970 x 250 (Billboard): One of the largest standard sizes. Offers flexibility for scaling down to almost anything.
- 336 x 280 (Large Rectangle): A good, large, squarish format. Often a safe bet as it's relatively balanced and scales down well to the popular 300x250.
Why not start with the smallest? Scaling up significantly can sometimes reveal imperfections or make text look slightly less crisp, although InDesign's vector text engine is excellent. Starting larger gives you more detail to work with.
Recommendation: I'd lean towards the 336 x 280 (Large Rectangle) or 728 x 90 (Leaderboard) depending on the general orientation of your designs. If you plan to make many sizes, starting even bigger like 970x250 might be slightly better. Ensure your template uses vector logos and high-resolution images if possible.
InDesign ExtendScript (JavaScript - JSX)
//@target indesign
// Script Name: Resize Banner Template for Google Ads
// Description: Duplicates the active InDesign document and resizes it
// to standard Google Web Banner ad sizes, scaling content proportionally.
(function() {
// --- Configuration: Define Target Banner Sizes ---
// Add or remove sizes as needed. Use pixels.
var targetSizes = [
{ name: "Medium Rectangle", width: 300, height: 250 },
{ name: "Large Rectangle", width: 336, height: 280 },
{ name: "Leaderboard", width: 728, height: 90 },
{ name: "Half Page", width: 300, height: 600 },
{ name: "Large Leaderboard", width: 970, height: 90 },
{ name: "Billboard", width: 970, height: 250 },
{ name: "Skyscraper", width: 120, height: 600 },
{ name: "Wide Skyscraper", width: 160, height: 600 },
{ name: "Square", width: 250, height: 250 },
{ name: "Small Square", width: 200, height: 200 },
{ name: "Mobile Banner", width: 320, height: 50 },
{ name: "Large Mobile Banner", width: 320, height: 100 }
// Add more sizes here if needed
// { name: "Portrait", width: 300, height: 1050 },
// { name: "Netboard", width: 580, height: 400 },
];
// --- Main Script Logic ---
if (app.documents.length === 0) {
alert("Error: No document is open.\nPlease open your banner template document first.");
return;
}
var originalDoc = app.activeDocument;
var originalFilePath = originalDoc.filePath;
var originalName = originalDoc.name.replace(/\.indd$/i, ""); // Remove .indd extension
if (!originalFilePath) {
alert("Error: Please save your template document at least once before running the script.");
return;
}
alert("Starting Banner Resize Process.\n" + targetSizes.length + " sizes will be generated in the same folder as the template.");
// Process each target size
for (var i = 0; i < targetSizes.length; i++) {
var target = targetSizes[i];
var newDoc = null; // Initialize newDoc
try {
// 1. Duplicate the Original Document
// Using duplicate is safer as it preserves more settings
newDoc = originalDoc.duplicate();
// Ensure we are working with the new document
app.activeDocument = newDoc;
// 2. Set Document Units to Pixels (Crucial for Web Work)
newDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.PIXELS;
newDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.PIXELS;
// Optional: Set ruler origin if needed, default is page corner which is usually fine
// newDoc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
// 3. Resize the Page
// Use Layout Adjustment temporarily? Better to scale content directly.
// Let's resize the page first.
newDoc.documentPreferences.pageWidth = target.width + "px";
newDoc.documentPreferences.pageHeight = target.height + "px";
// 4. Select All Items on the First Page and Group
var pageItems = newDoc.pages[0].pageItems.everyItem().getElements();
if (pageItems.length > 0) {
// Deselect all first to be safe
newDoc.select(NothingEnum.NOTHING);
// Select all items specifically on the page (not masters, not pasteboard)
newDoc.pages[0].select(); // Selects the page itself, alternative way
// A more robust way to select only items *on* the page
var itemsToSelect = [];
for(var pi=0; pi < pageItems.length; pi++){
try {
// Check if the item's parent is the page (or spread) - filters out master page items etc.
if (pageItems[pi].parentPage === newDoc.pages[0] || pageItems[pi].parent.constructor.name === "Spread") {
itemsToSelect.push(pageItems[pi]);
}
} catch(e) { /* Ignore items that might cause errors, like locked items maybe? */ }
}
if (itemsToSelect.length > 0) {
newDoc.select(itemsToSelect);
// Group the selected items
var itemGroup = newDoc.groups.add(newDoc.selection);
// 5. Calculate Scaling Factor
var groupBounds = itemGroup.visibleBounds; // [y1, x1, y2, x2] in current units (pixels)
var groupWidth = groupBounds[3] - groupBounds[1];
var groupHeight = groupBounds[2] - groupBounds[0];
// Avoid division by zero if group has no size
if (groupWidth <= 0 || groupHeight <= 0) {
alert("Warning: Content on page 1 of " + originalName + " appears to have zero width or height. Skipping scaling for " + target.name);
itemGroup.ungroup(); // Ungroup if we are not scaling
} else {
var scaleX = target.width / groupWidth;
var scaleY = target.height / groupHeight;
var scaleFactor = Math.min(scaleX, scaleY); // Scale proportionally to fit *within* the new page
// 6. Resize the Group
// Using transform method for proportional scaling from center
var scaleMatrix = app.transformationMatrices.add({ horizontalScaleFactor: scaleFactor, verticalScaleFactor: scaleFactor });
itemGroup.transform(
CoordinateSpaces.PARENT_COORDINATES, // Relative to the page/spread
AnchorPoint.CENTER_ANCHOR, // Scale from the center
scaleMatrix, // Apply the calculated scale
undefined, // No repositioning during transform
true // Consider stroke weight etc.
);
// 7. Center the Scaled Group on the New Page
var scaledGroupBounds = itemGroup.visibleBounds;
var scaledGroupWidth = scaledGroupBounds[3] - scaledGroupBounds[1];
var scaledGroupHeight = scaledGroupBounds[2] - scaledGroupBounds[0];
var targetCenterX = target.width / 2;
var targetCenterY = target.height / 2;
var groupCurrentCenterX = scaledGroupBounds[1] + scaledGroupWidth / 2;
var groupCurrentCenterY = scaledGroupBounds[0] + scaledGroupHeight / 2;
var moveX = targetCenterX - groupCurrentCenterX;
var moveY = targetCenterY - groupCurrentCenterY;
itemGroup.move(undefined, [moveX, moveY]); // Move by the calculated offset
// 8. Ungroup (Optional - keeps items editable individually)
itemGroup.ungroup();
}
} else {
alert("Warning: No items found directly on page 1 of " + originalName + " to resize for " + target.name + ". Master items are not scaled by this script.");
}
} else {
// No items on page 1 - just save the blank resized doc
alert("Warning: No items found on page 1 of " + originalName + " for size " + target.name);
}
// 9. Save the New Document
var newFileName = originalName + "_" + target.width + "x" + target.height + "_" + target.name.replace(/ /g,"_") + ".indd";
var newFilePath = new File(originalFilePath + "/" + newFileName);
newDoc.save(newFilePath);
// 10. Close the New Document
newDoc.close(SaveOptions.YES); // Already saved, but confirms closure
} catch (e) {
alert("An error occurred while processing size: " + target.name + "\nError: " + e.message + "\nLine: " + e.line);
// Attempt to close the new document if it exists and encountered an error
if (newDoc && !newDoc.closed) {
newDoc.close(SaveOptions.NO); // Close without saving changes if error occurred
}
}
} // End loop through target sizes
alert("Banner resizing process finished!");
})(); // End main function wrapper
How to Use:
-
Prepare Your Template:
- Create your banner design in InDesign. Use the recommended starting size (e.g., 336x280 pixels). Set your document intent to "Web" (
File > Document Setup... > Intent: Web) to easily work in pixels.
- Place all essential design elements (text, logos, images, shapes) on the first page of the document. Avoid putting critical elements only on master pages if you want them scaled.
- Ensure text frames are appropriately sized (not excessively large empty areas). Auto-Sizing text frames (
Object > Text Frame Options > Auto-Size) can sometimes be helpful but test carefully.
- Save your template document (
.indd) in a known location.
-
Install the Script:
- Open InDesign.
- Go to
Window > Utilities > Scripts.
- Right-click (or Ctrl-click on Mac) on the "User" folder in the Scripts panel and choose "Reveal in Finder" (Mac) or "Reveal in Explorer" (Windows).
- Copy the
.jsx script file (save the code above as a plain text file named something like Resize Google Banners.jsx) into this "Scripts" folder.
-
Run the Script:
- Keep your saved banner template document open and active in InDesign.
- Go back to the Scripts panel in InDesign.
- Double-click the
Resize Google Banners.jsx script under the "User" folder.
- The script will alert you it's starting.
- It will then create, resize, scale, save, and close a new
.indd file for each size defined in the targetSizes array. These new files will appear in the same folder as your original template.
-
Review and Export:
- Open the generated
.indd files.
- Review each size. While the script does proportional scaling, minor adjustments might be needed, especially for text line breaks or readability at very small sizes.
- Export each
.indd file to your desired web format (JPG, PNG, GIF) using File > Export....
Important Considerations:
- Text Scalability: Grouping all items before scaling is the key. InDesign scales text point size proportionally within the group. Ensure your initial text sizes are readable and well-placed.
- Locked Layers/Items: The script might fail or skip items that are locked. Unlock everything you want to be resized before running.
- Master Pages: Items exclusively on master pages will not be selected or scaled by this script, as it focuses on
pages[0]. Design accordingly.
- Complex Layouts: For very complex layouts with overlapping items or intricate dependencies, automatic scaling might require manual touch-ups afterward.
- File Paths: Ensure your template is saved before running, as the script needs a path to save the new files.
- Units: The script explicitly sets the new documents' units to Pixels, which is essential for web banners.
- Error Handling: Basic error handling is included, but complex document issues could still cause problems.