That is because you are manipulating spreads. To just add 'any' page to a document, add it directly to the document.pages object. That way it will work exactly like in the interface: it only adds another spread when the current one is 'full' according to its master spread.
Hmmm, I tried changing the code to:
var mySpread = myDocument.spreads.add(); myPage = myDocument.pages.add();
But the new page is added to a new spread, not the just-created mySpread. I also tried adding more pages to my master spread, but that didn't have any effect. Could you elaborate on what you mean when you say "it only adds another spread when the current one is 'full' according to its master spread."
The goal here is that I have a folder full of multi-page PDFs, and I want to place them on inDesign pages, with all the pages of a placed PDF together in a spread. The PDFs have differing numbers of pages. I'm able to do this manually within InDesign, but as you can imagine it's pretty tedious with a few dozen PDFs of 1-5 pages each.
P.S. the html DOM reference you put together is super helpful, thanks for that!
You could just apply the number of necessary pages to a document by setting one value.
var numberOfPagesInPDF = 123; app.documents.documentPreferences.pagesPerDocument = numberOfPagesInPDF;
To be clear, I'm not having trouble adding pages to the InDesign document. I'm having trouble controlling whether the pages are added to the existing spread, or if a new spread is automatically created. I would like to have all of the placed PDF pages together on a spread. I'm able to do this manually.
2 people found this helpful
So you have to add two ingredients to the mix:
Aha! Thank you, that was the missing piece I wasn't understanding-- I had "Allow Document Pages to Shuffle" and "Allow Selected Spread to Shuffle" unchecked in the app, and it seems that new spreads that are added have the "Allow Selected Spread to Shuffle" on by default. At least I think that was what was happening, those options are a little confusing to me.
For the benefit of anyone else facing this issue, the code that worked for me was:
myDoc.documentPreferences.preserveLayoutWhenShuffling = true;
myDoc.documentPreferences.allowPageShuffle = false;
mySpread.allowPageShuffle = false;
That's why I pointed you to the fact, that allowPageShuffle is a property of the documentPreferences and a particular spread as well.
I'm glad, it's working for you now.
Note: Often it helps to see what the condition an object is in (your document, your added spread) if you try the task within the UI of InDesign and write out the steps you did as tasks that should be worked on for your script. You could have remembered then, that you probably changed the allowPageShuffle value for a particular spread before adding pages to that spread.