Copy link to clipboard
Copied
Does anyone have any ideas for an InDesign Script to set Masterspread page sizes?
I have been trying to change the page sizes in a Masterspread using VBScript but with no sucess and can't find any reference for it.
I thought it would probably be something in MasterSpread.Preferences but I've tried several variations of
PageWidth, PageHeight, Width, Height etc
eg
myDocument.MasterSpread.Preferences.PageWidth=120
myDocument.MasterSpread.Preferences.Width=120
myDocument.MasterSpread.PageWidth=120
myDocument.MasterSpread.Width=120
myDocument.MasterSpread.Page(0).Preferences.PageWidth=120
myDocument.MasterSpread.Page(0).Preferences.Width=120
but with no success.
Any suggestions would be gratefully appreciated.
Hi @chrisnaylor , try the resize() method. This is JS
//6"x9" page. By default the resize() method expects points
var w = 432
var h = 648
//the document‘s first masterSpread
var myLP=app.activeDocument.masterSpreads[0].pages[0];
var myRP=app.activeDocument.masterSpreads[0].pages[1];
myLP.resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h])
myRP.resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.CENTER_ANCHOR,Resiz
...
Copy link to clipboard
Copied
Hi @chrisnaylor , try the resize() method. This is JS
//6"x9" page. By default the resize() method expects points
var w = 432
var h = 648
//the document‘s first masterSpread
var myLP=app.activeDocument.masterSpreads[0].pages[0];
var myRP=app.activeDocument.masterSpreads[0].pages[1];
myLP.resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h])
myRP.resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h])
Copy link to clipboard
Copied
Many thanks for your posting - that was very helpful!
I have converted your sugegstion into VBScript and it seems to work well, as follows:
myArray = Array(mypageWidth,mypageHeight)
myDocument.MasterSpreads(1).Pages(1).Resize idCoordinateSpaces.idInnerCoordinates, idAnchorPoint.idCenterAnchor,idResizeMethods.idReplacingCurrentDimensionsWith, myArray
myDocument.MasterSpreads(1).Pages(2).Resize idCoordinateSpaces.idInnerCoordinates, idAnchorPoint.idCenterAnchor,idResizeMethods.idReplacingCurrentDimensionsWith, myArray
The only snag I'm hitting is that the measurments seem to assume points - and I'm having difficulty working out how to get it to use millimeters.
I have tried various approaches, such as :
myInDesign.ScriptPreferences.MeasurementUnit = idMeasurementUnits.idmillimeters
and
myDocument.MasterSpreads.Item(1).HorizontalMeasurementUnits = idMeasurementUnits.idmillimeters
But none of them seem to work.
Any suggestions would be gratefully appreciated.
Copy link to clipboard
Copied
I had no idea that Google is broken today? 😉
Copy link to clipboard
Copied
Many thanks for your posting - I had actually seen that reference but I didn't seem able to get that approach to work on the Master Spreads..
Copy link to clipboard
Copied
Measurement units are global for the whole document - you can't have different spreads with different units.
Copy link to clipboard
Copied
The resize() method has a 6th parameter which you have to set to true in order to resize using rulers, otherwise it uses points no matter what the measurement units are set to.
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Page.html#d1e203601__d1e205188
Copy link to clipboard
Copied
That was brilliant! I appreciate your help.
This is now the modified VBscript:
myArray = Array(mypageWidth,mypageHeight)
myDocument.MasterSpreads(1).Pages(1).Resize idCoordinateSpaces.idPageCoordinates, idAnchorPoint.idTopLeftAnchor,idResizeMethods.idReplacingCurrentDimensionsWith, myArray,,True
myDocument.MasterSpreads(1).Pages(2).Resize idCoordinateSpaces.idPageCoordinates, idAnchorPoint.idTopLeftAnchor,idResizeMethods.idReplacingCurrentDimensionsWith, myArray,,True
As well as setting the 6th parameter to True, it looks like the 1st parameter also needs to be set to Page Coordinates for it to work.
There is only one remaining anomaly that's puzzling me - and which started me off on this: that is that the Print Booklet option on the resulting document doesn't work if the Master Pages sizes have been changed from their original size even thought they now match the size of other pages in the document. It.claims that the "Active Document uses multiple page sizes. Print booklet oly works with consistent page sizes."
As far as I can see, all the page sizes on docuemnts and masters are now the same - but resizing them seems to have caused problems for Print Booklet.
Copy link to clipboard
Copied
You might have to loop through all the pages to make sure they are the same size. Also, rather than setting the ruler units and setting the extra parameter, it’s pretty easy to convert millimeters to points—multiply by 2.83465.
This sets the size for all of the pages and master pages to 180 x 230 millimeters
//n * 2.83465 converts millimeters to points
var w = 180 * 2.83465
var h = 230 * 2.83465
var p = app.activeDocument.pages;
var ms = app.activeDocument.masterSpreads.everyItem().pages.everyItem().getElements();
for (var i = 0; i < ms.length; i++){
ms[i].resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h])
ms[i].resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h])
};
for (var j = 0; j < p.length; j++){
p[j].resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h])
p[j].resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h])
};
Copy link to clipboard
Copied
Many thanks for your posting - I appreciate the interest you are taking in this!
I had thought about using a conversion from mm to points but wondered whether this might cause any problems with rounding errors - so I decided to stay with the guidance you gave on the 6th parameter (and the corresponding 2nd parameter) to get it to adopt the document ruler measurements.
I have tried various methods to get Print Booklet to agree that all the pages have the same dimensons - but, so far, without success.
For instance:
For i=1 to myDocument.MasterSpreads.Count
For j=1 to myDocument.MasterSpreads(i).Pages.Count
myDocument.MasterSpreads(i).Pages(j).Resize idCoordinateSpaces.idPageCoordinates, idAnchorPoint.idTopLeftAnchor,idResizeMethods.idReplacingCurrentDimensionsWith, myArray,,True
Next
Next
To my mind, this ought to set all of the master spreads and pages to the new dimensions and, checking them out manually in InDesign they do all seem to be the same size - but Print Booklet never agrees!
I am rather curious about your latest code suggestion: why, in both loops, did you repeat the resize command? Am I missing something?
Copy link to clipboard
Copied
But you are ONLY resizing Pages on Master Spreads - not all pages in the document?
Have not used Print Booklet - are you sure the error is about Masters or regular Pages? Because, why would it care about Masters - when it will process Pages?
Copy link to clipboard
Copied
Many thanks for the posting - I tried adding the following pages loop, but it didn't resolve the problem:
For i=1 to myDocument.Pages.Count
myDocument.Pages(i).Resize idCoordinateSpaces.idPageCoordinates, idAnchorPoint.idTopLeftAnchor,idResizeMethods.idReplacingCurrentDimensionsWith, myArray,,True
'Next
I can't really see where the error is coming from, but it goes like this:
The document starts off by creating itself from a template of a given size. It then resizes itself to a new size. After that, Print Booklet continues to insist that there are multiple page sizes there. That was why I was giving so much precedence to resizing Master Pages, in case that was where the problem lay.
Copy link to clipboard
Copied
checking them out manually in InDesign they do all seem to be the same size
How are you checking? With the Pages tool and Transform panel? If you run my JS example does it work? I added the pages loop because I did not want to assume there were no overrides to the pages.
Copy link to clipboard
Copied
Many thanks for your posting - I had been checking the page sizes via the File...Document Setup menu options and they all looked good. But the Print Booklet error persists.
I have also tried your js code but, sadly, that gave the same problem with PrintBooklet.
Copy link to clipboard
Copied
I had been checking the page sizes via the File...Document Setup menu options and they all looked good.
That wouldn’t necessarily work—a document can have any number of custom sized pages. You can transform any page via the Pages tool, which would be a parent page override.
Can you share the InDesign file? No need to package, just attach it to a reply.
Copy link to clipboard
Copied
Many thanks for your interest in the matter - I attach the template file from which everything starts.
I have had to rename it with extension .indd as extension .indt was not accepted on the upload.
Print Booklet works fine from a document created from this file - until everything is resized.
Copy link to clipboard
Copied
Why can't you do a booklet from the PDF?
Copy link to clipboard
Copied
I’m not seeing a problem with the template file. If I make 8 pages and run this:
//n * 2.83465 converts millimeters to points
var w = 150 * 2.83465
var h = 220 * 2.83465
var p = app.activeDocument.pages;
var ms = app.activeDocument.masterSpreads.everyItem().pages.everyItem().getElements();
for (var i = 0; i < ms.length; i++){
ms[i].resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h])
ms[i].resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h])
};
for (var j = 0; j < p.length; j++){
p[j].resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h])
p[j].resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h])
};
I get this:
150mm x 220mm Pages
Can you post a layout that Print Booklet rejects?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Still can’t see the problem. You would need at least 4 pages to do an imposition, so Print Booklet is adding blanks in order to get the 4 pages, but it’s letting me print:
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Many thanks again for your efforts.
I have been trying to pin down the problem and have found that if I open the template file I posted, insert pages (say, 7 as you did or, even, just 1) and then resize using your js code, Print Booklet works well, as you have shown.
However, if I open the template file, run your js code to resize, and then insert pages after the resize, Print Booklet fails with multiple page size error. Running the js resizing code again doesn't then solve the problem.
I'm still investigating...
Copy link to clipboard
Copied
If you are adding pages after running the script try also changing the document setup width and height—in case you are adding pages with a [None] parent:
var doc = app.activeDocument;
//set rulers to millimeters
doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
var w = 150
var h = 220
var p = doc.pages;
var ms = doc.masterSpreads.everyItem().pages.everyItem().getElements();
//reset document setup
doc.documentPreferences.pageHeight = h
doc.documentPreferences.pageWidth = w
//resize master pages using ruler units
for (var i = 0; i < ms.length; i++){
ms[i].resize (CoordinateSpaces.PAGE_COORDINATES,AnchorPoint.CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h], true, true)
ms[i].resize (CoordinateSpaces.PAGE_COORDINATES,AnchorPoint.CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h], true, true)
};
//resize pages using ruler units
for (var j = 0; j < p.length; j++){
p[j].resize (CoordinateSpaces.PAGE_COORDINATES,AnchorPoint.CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h], true, true)
p[j].resize (CoordinateSpaces.PAGE_COORDINATES,AnchorPoint.CENTER_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[w,h], true, true)
};
Copy link to clipboard
Copied
Why each for() is doind the same .resize() operation twice?
Copy link to clipboard
Copied
Yes, just need one—it’s was a cut and paste from the very first 2 page script
Find more inspiration, events, and resources on the new Adobe Community
Explore Now