Skip to main content
Dec 18, 2025 1:57 PM UTC
Question

Need a Help on Page width only not to change page Height

#target "InDesign";
var mainFunction = function(args) {
    var pageNum = args[0];
    var newWidth = args[1];
    var doc = app.activeDocument;
    var pageIndex = pageNum - 1;

    if (pageIndex >= 0 && pageIndex < doc.pages.length) {
        var targetPage = doc.pages[pageIndex];
        doc.documentPreferences.allowPageShuffle = false;
        var currentHeight = targetPage.bounds[2] - targetPage.bounds[0];

        targetPage.resize(
            CoordinateSpaces.INNER_COORDINATES,
            AnchorPoint.TOP_LEFT_ANCHOR,
            ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
            [newWidth, currentHeight]
        );

        alert("Page " + pageNum + " resized successfully to " + newWidth.toFixed(2) + " pts.");
    } else {
        alert("Error: Page number " + pageNum + " is out of range.");
    }
};

var showDialogAndExecute = function() {
    if (app.documents.length == 0) {
        alert("Please open an InDesign document and try again.");
        return;
    }

    var doc = app.activeDocument;
    var dialog = app.dialogs.add({name: "Resize Specific Page"});
    var currentWidth = doc.pages[0].bounds[3] - doc.pages[0].bounds[1];

    with(dialog.dialogColumns.add()){
        with(dialogRows.add()){
            staticTexts.add({staticLabel: "Page Number (Absolute):"});
            var pageNumberInput = integerEditboxes.add({editValue: 1}); 
        }
        with(dialogRows.add()){
            staticTexts.add({staticLabel: "New Width (Points):"});
            var newWidthInput = realEditboxes.add({editValue: currentWidth});
        }
    }

    if (dialog.show() == true) {
        var pNum = pageNumberInput.editValue;
        var nWidth = newWidthInput.editValue;
        dialog.destroy();
        app.doScript(
            mainFunction, 
            ScriptLanguage.JAVASCRIPT, 
            [pNum, nWidth], 
            UndoModes.ENTIRE_SCRIPT, 
            "Resize Page"
        );
    } else {
        dialog.destroy();
    }
};

showDialogAndExecute();

3 replies

rob day
Community Expert
Community Expert
Dec 18, 2025 3:09 PM UTC

Hi @Karthikeyan_B8689 , The default transform method expects points for width and height, so you can use the measurementEditbox instead of realEditbox, which returns points and set the script’s measurement units to points. Try this:

 

//#target "InDesign";
var mainFunction = function(args) {
    var pageNum = args[0];
    var newWidth = args[1];
    var doc = app.activeDocument;
    var pageIndex = pageNum - 1;

     if (pageIndex >= 0 && pageIndex < doc.pages.length) {
        var targetPage = doc.pages[pageIndex];
        doc.documentPreferences.allowPageShuffle = false;
        var currentHeight = targetPage.bounds[2] - targetPage.bounds[0];
        targetPage.resize(
            CoordinateSpaces.INNER_COORDINATES,
            AnchorPoint.TOP_LEFT_ANCHOR,
            ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
            [newWidth, currentHeight]
        );

        alert("Page " + pageNum + " resized successfully to " + newWidth.toFixed(2) + " pts.");
    } else {
        alert("Error: Page number " + pageNum + " is out of range.");
    } 
};

var showDialogAndExecute = function() {
    if (app.documents.length == 0) {
        alert("Please open an InDesign document and try again.");
        return;
    }
   
    var currentWidth = app.activeDocument.pages[0].bounds[3] - app.activeDocument.pages[0].bounds[1];
    var dialog = app.dialogs.add({name: "Resize Specific Page"});
    with(dialog.dialogColumns.add()){
        with(dialogRows.add()){
            staticTexts.add({staticLabel: "Page Number (Absolute):"});
            var pageNumberInput = integerEditboxes.add({editValue: 1}); 
        }
        with(dialogRows.add()){
            staticTexts.add({staticLabel: "New Width:"});
            //var newWidthInput = realEditboxes.add({editValue: currentWidth});
            //measurementEditbox returns measurements as points, which the transform method needs
            var newWidthInput = measurementEditboxes.add({editUnits:MeasurementUnits.INCHES, editValue:currentWidth});
        }
    }

    if (dialog.show() == true) {
        var pNum = pageNumberInput.editValue;
        var nWidth = newWidthInput.editValue;
        app.doScript(
            mainFunction, 
            ScriptLanguage.JAVASCRIPT, 
            [pNum, nWidth], 
            UndoModes.ENTIRE_SCRIPT, 
            "Resize Page"
        );
        dialog.destroy();
    } else {
        dialog.destroy();
    }
};

// Use POINTS for measurements—the transform method defaults to points
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
showDialogAndExecute();
app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;
Translate
Mike Witherell
Community Expert
Community Expert
Dec 18, 2025 2:31 PM UTC

Why are you not simply changing the parent page with the Page tool, or visiting File > Document Setup?

Translate
Mike Witherell
Dec 18, 2025 2:36 PM UTC

Need to do many pages

Translate