Skip to main content
December 18, 2025
Question

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

  • December 18, 2025
  • 2 replies
  • 104 views
#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();

2 replies

rob day
Community Expert
Community Expert
December 18, 2025

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;
Mike Witherell
Community Expert
Community Expert
December 18, 2025

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

Mike Witherell
December 18, 2025

Need to do many pages