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();