Copy link to clipboard
Copied
Hello!
Can someone please modify this script for me, because my document have to be split with double pages, but with this script they are separated into individual pages... Thank you very much!
/*
CreateIndividualPages.jsx
Makes new INDD files of each page of a document, named as the page number
*/
var doc = app.activeDocument;
var pages = doc.pages.everyItem().getElements();
var docName = doc.name.replace(".indd", "");
var filePath = doc.filePath;
// set this value to the number of pages each document should have.
var delta = 3;
for (var p = 0; p < pages.length; p = p + 50) {
var keyPage = pages[p];
var nextKeyPage = p + 50;
var newDoc = app.documents.add();
newDoc.name = docName + "_" + (p + 1) + ".indd";
// copy key page to new document
keyPage.duplicate(LocationOptions.BEFORE, newDoc.pages[0]);
// remove staring page of new document
newDoc.pages[1].remove();
// for each page after the keyPage and up to the nextKeyPage, (skip first page)
for (var k = p + 1; k < nextKeyPage; k++) {
// if page exists, append to newDoc
if (pages[k] !== undefined) {
pages[k].duplicate(
LocationOptions.AFTER,
newDoc.pages[newDoc.pages.length - 1]
);
}
}
newDoc.save(File(filePath + "/" + newDoc.name));
newDoc.close(SaveOptions.NO);
}
alert("Done!");
2 Correct answers
Hi @aniri5j9ox8tw2ln and others, I'm not sure if the script Peter posted might do the trick, but I've written my own version for fun. Maybe it will be useful, too. I don't duplicate to new documents, because then you lose lots of document settings. It's a quick script so will definitely have bugs in some cases. I'm tempted to add I added a UI.
- Mark
/**
* @file Divide Document.js
*
* Outputs new Indesign documents comprising
* sequences of pages of the active document.
*
* Makes attempt
...
@aniri5j9ox8tw2ln I mean my script does that exactly, so feel free to try it.
You just need to set pageCount to
pageCount: 50,
and you can also adjust this line:
fileNameTemplate: "Output/{docName}_pages {pageStart}-{pageEnd}.indd",
This is how the output folder and file name is derived.
- Mark
Copy link to clipboard
Copied
Do you need to preserve spreads layout - or just 2x pages per document?
Copy link to clipboard
Copied
Hello everyone! I would like to split a 200-page document into several parts and have therefore set the division to 50 pages each. But the pages should remain double-sided as my original layout. In the end, I would like to have my document in several ID files in the Finder, which then have in addition to the file name 1, 2, 3, 4 etc. in it... Thank you very much for your effort and the tests so far. Which script is the right one for me?
Copy link to clipboard
Copied
So you need to split 200 pages document - into 4x 50 pieces?
Then just create a new blank document - with the same page size, switch back to your document, go to Pages panel, hamburger menu, Move, type 1-50 as page range, select as destination newly created document, location as beginning, untick delete pages and then OK / done / whatever there is to confirm.
Switch to new document - delete last page - save with a new name.
Repeat above X times - for a different ranges - 51-100, 101-150, etc.
It will take you a minute.
Copy link to clipboard
Copied
Sure, I know this function to move/copy the pages directly from ID to new documents. But I wanted to do it faster and easier....
Copy link to clipboard
Copied
Sure, I know this function to move/copy the pages directly from ID to new documents. But I wanted to do it faster and easier....
By aniri5j9ox8tw2ln
For one file? Or do you have more files to process on a daily basis?
Copy link to clipboard
Copied
No, not a daily thing. but it happens occasionally...
In any case, I now have problems finding the right script. So many have been posted here that I don't know my way anymore... sorry!
Copy link to clipboard
Copied
No, not a daily thing. but it happens occasionally...
In any case, I now have problems finding the right script. So many have been posted here that I don't know my way anymore... sorry!
By aniri5j9ox8tw2ln
If you work on Windows - you could use my ID-Tasker tool - isn't free but can execute pretty much all clicks / operations you can do manually in the InDesign - including moving pages between documents - so as long as you know what to do - you don't need to know how to write scripts = don't have to wait for someone to write script for you.
Copy link to clipboard
Copied
No, Mac OS system...
Copy link to clipboard
Copied
Another approach is to save the full document multiple times with new names, then delete content and pages from each of the copies leaving only what you want for each individual "section". This will guarantee that your styles are preserved.
Copy link to clipboard
Copied
If you need to divide a threaded story whn you do this you can use this script:
//DESCRIPTION: Splits story at the selected text frame.
// The selected frame becomes the first of the new story.
// Note that the behavior when an overset last frame is selected
// is different from that of the break-out text frame script.
// This script moves the overset text to the second story while
// breaking out the last frame leaves the overset text attached to the first story.
if ((app.documents.length != 0) && (app.selection.length != 0)) {
var myFrame = app.selection[0];
if (myFrame.constructor.name != "TextFrame") {
errorExit('Please select a text frame');
}
var myStory = myFrame.parentStory;
var mySplit = myFrame.textFrameIndex;
var myTot = myStory.textFrames.length;
// Because of the possibility of tables, we must always work from the back
var myStart = myTot - 1;
var myEnd = mySplit;
// Nothing to do if user has selected first frame.
if (myEnd != 0) {
if (myStart > myEnd) {
var myPrevFrame = splitMe(myStory.textFrames[myStart]);
myStart--;
for (var i = myStart; i> myEnd; i--) {
var myNewFrame = splitMe(myStory.textFrames[i]);
myPrevFrame.previousTextFrame = myNewFrame;
myPrevFrame = myNewFrame;
}
}
// Now we deal with the last frame
myFrame = myStory.textFrames[myEnd]
try {
myIndex = myFrame.characters[0].index;
stEnd = myStory.length - 1;
myText = myStory.texts[0].characters.itemByRange(myIndex,stEnd);
} catch (e) { } // Ignore; happens if last character is a table or frames are empty.
myNewFrame = myFrame.duplicate();
try{myText.remove();}catch(e){} //ignore empty frame
myFrame.remove();
try{myPrevFrame.previousTextFrame = myNewFrame;}catch(e){} //fails if one frame only
//Finally, if, and only if, the split is mid-table, myStory is now overset
if (myStory.textFrames[-1].overflows) {
myTable = myStory.characters[-1].tables[0];
myNewTable = myNewFrame.parentStory.characters[0].tables[0];
myRowCount = myNewTable.rows.length;
myTable.rows.itemByRange(0 - myRowCount,-1).remove();
}
}
} else {
errorExit();
}
// +++++++ Functions Start Here +++++++++++++++++++++++
function splitMe(myFrame) {
myDupeFrame = myFrame.duplicate();
while(myDupeFrame.contents.length > 0) {
myDupeFrame.texts[0].remove();
}
myFrame.remove();
return myDupeFrame;
}
function errorExit(message) {
if (arguments.length > 0) {
if (app.version != 3) { beep() } // CS2 includes beep() function.
alert(message);
}
exit(); // CS exits with a beep; CS2 exits silently.
}
// +++++++ Script Ends Here ++++++++++++++++++++++++++
Again, a very old script, I think by @dAvE Saunders but it should still work.
Copy link to clipboard
Copied
Even before that, I've always done that...
But I just thought it would be better with a script 😉
Copy link to clipboard
Copied
Even before that, I've always done that...
But I just thought it would be better with a script 😉
By aniri5j9ox8tw2ln
Scripts have their place, as does AI, but you shouldn't presume they are necessarliy better than using your own brain.
Copy link to clipboard
Copied
@aniri5j9ox8tw2ln I mean my script does that exactly, so feel free to try it.
You just need to set pageCount to
pageCount: 50,
and you can also adjust this line:
fileNameTemplate: "Output/{docName}_pages {pageStart}-{pageEnd}.indd",
This is how the output folder and file name is derived.
- Mark
Copy link to clipboard
Copied
@m1b My apologies for not having studied your script.
I've had a new look at it and I think it might be what the OP wants. I tend towards the more manual approach to chopping up a file, though, in case you want to divide it mid-page.
Copy link to clipboard
Copied
Hi @m1b ... Thank you very much for your help, I now had time to take a closer look at all the scripts and yours effectively does what I'm looking for. I can then also change the number at pageCount:, so I can also manage it individually for other documents with fewer pages. I'm glad I found a script solution. I know there are some manual solutions, but working with a script appealed to me more!
Copy link to clipboard
Copied
Hi m1b ... Thank you very much for your help, I now had time to take a closer look at all the scripts and yours effectively does what I'm looking for. I can then also change the number at pageCount:, so I can also manage it individually for other documents with fewer pages. I'm glad I found a script solution. I know there are some manual solutions, but working with a script appealed to me more!
By aniri5j9ox8tw2ln
Are you fully aware of the drawback - that you'll lose threading between TextFrames located on different pages?
Are you trying to split DataMerged document?
Copy link to clipboard
Copied
> Are you fully aware of the drawback - that you'll lose threading between TextFrames located on different pages?
I believe I fixed that issue.
@Peter Spier haha no problem! I love that the OPs problem is TOO MANY scripts! I actually learned quite a lot from this exercise, even though I doubt that I'd ever need this exact script myself. 🙂
@aniri5j9ox8tw2ln I've put a UI now so that will make things easier.
Copy link to clipboard
Copied
And between Spreads?
Copy link to clipboard
Copied
@m1b That's wonderful! It works perfectly, thank you again!
Btw: I had also tried to change my original script with chatgpt, but it didn't work! So a high on the community! 🙂
Copy link to clipboard
Copied
You're welcome!
Yes ChatGPT can be a great help but you need to understand what you're getting. It is very common for ChatGPT to make up (confabulate) API features that don't actually exist, for example.
- Mark
Copy link to clipboard
Copied
Assuming you are printing this document, why not do this in Acrobat with the Split feature? That way, your original InDesign document intact for future editing.
Copy link to clipboard
Copied
That's not what I want, I don't have to print it. I especially need the split ID file, because it will end up being a different version (different language), so I have to be able to work on it. But for certain reasons I need several separate files from the 200-page document...
Copy link to clipboard
Copied
That's not what I want, I don't have to print it. I especially need the split ID file, because it will end up being a different version (different language), so I have to be able to work on it. But for certain reasons I need several separate files from the 200-page document...
By aniri5j9ox8tw2ln
Can you elaborate more?
Copy link to clipboard
Copied
I have a document which, as I said, has over 200 pages, I had to have this document translated (via an online service where you can upload the .idml files), after the translation I have to split my document into several parts so that I can pass it on to several people what the translated chapters correct and edit. After that, I can put these parts back together into a document and have my new version in the other language.


-
- 1
- 2