Copy link to clipboard
Copied
I have a task at work that involves taking a 40-90 page inDesign file every week and saving it as individual .indd files ( Page1.indd, Page2 .indd, Page3 .indd, etc. ) so that more than one person can work on the pages at once. I'm honestly really annoyed that inDesign doesn't have any kind of native feature for this by now, since you can find people looking for the answer to the same problem 7 or 8 years ago...
Additionally, it seems all script fixes for this issue don't work on newer versions of inDesign. I really need one that works for CS6 but even one that worked for CC would be better than the endless wall of broken links from 2012ish that I've found so far. I'm more than willing to try and make one myself but I have absolutely zero experience in script writing. Does anyone have any script answer to this or at least could point me where to start?
Pages Extractor 1.1 - ©www.loicaigon.com
(I have tested in both CS6 and CC2018)
...// 1. Control for documents open. If true, the script launches the dialog
if(app.documents.length >0)
{
var doc = app.documents[0];
if(doc.saved==true)
{
extractdlg();
}
else
{
alert("Please save you file first before processing the script");
}
}
else
{
alert("No documents open !");
}
// 2. Gathers many infos on the document.
function pageinfos()
{
var pg = doc.pages;
var pglg = pg.length;
var pFirst = Number(pg[0
Copy link to clipboard
Copied
Hi Mayaelaine,
Our Extract Pages script (not free) works with all the latest versions of InDesign, from CS6 onwards.
Check it out here: https://www.id-extras.com/products/extract-pages
HTH,
Ariel
Copy link to clipboard
Copied
Pages Extractor 1.1 - ©www.loicaigon.com
(I have tested in both CS6 and CC2018)
// 1. Control for documents open. If true, the script launches the dialog
if(app.documents.length >0)
{
var doc = app.documents[0];
if(doc.saved==true)
{
extractdlg();
}
else
{
alert("Please save you file first before processing the script");
}
}
else
{
alert("No documents open !");
}
// 2. Gathers many infos on the document.
function pageinfos()
{
var pg = doc.pages;
var pglg = pg.length;
var pFirst = Number(pg[0].name);
var pLast = Number(pg[pglg-1].name);
var pgHeigth = doc.documentPreferences.pageHeight;
var pgWitdh = doc.documentPreferences.pageWidth;
var docname = String(doc.fullName).replace(/\.indd$/, "");
var docpath = doc.filePath;
var docfullname = doc.fullName;
var infoarr = [pglg, pFirst, pLast, pgHeigth,pgWitdh,docname,docpath,docfullname];
return infoarr;
}
// 3. Main function. First part is the dialog
function extractdlg()
{
var docfile = String(pageinfos()[7]);
var dlg = app.dialogs.add({name : "Pages Extractor 1.1 - ©www.loicaigon.com"});
with(dlg)
{
var firstclmn = dialogColumns.add();
with(firstclmn)
{
var firstrow = dialogRows.add();
with(firstrow)
{
var clmn1 = dialogColumns.add();
with(clmn1)
{
var row1 = dialogRows.add();
row1.staticTexts.add({staticLabel : "Extract pages..."});
var row2 = dialogRows.add();
with(row2)
{
var r2c2 = dialogColumns.add();
with(r2c2)
{
var r2c2r1 = dialogRows.add();
var pgStart = r2c2r1.realEditboxes.add({editValue:pageinfos()[1], minWidth: 30});
}
var r2c3 = dialogColumns.add();
with(r2c3)
{
var r2c3r1 = dialogRows.add();
r2c3r1.staticTexts.add({staticLabel : "to"});
}
var r2c4 = dialogColumns.add();
with(r2c4)
{
var r2c4r1 = r2c4.dialogRows.add();
var pgEnd = r2c4r1.realEditboxes.add({editValue:pageinfos()[2], minWidth: 30});
}
}
}
}
var secondrow = dialogRows.add();
with(secondrow)
{
var clmn2 = dialogColumns.add();
with(clmn2)
{
var row2 = dialogRows.add();
with(row2)
{
var sepbox = checkboxControls.add({staticLabel: "Extract as separate pages", checkedState:false});
}
}
}
var thirdrow = dialogRows.add();
with(thirdrow)
{
var clmn3 = dialogColumns.add();
with(clmn3)
{
var row3 = dialogRows.add();
with(row3)
{
var rembox = checkboxControls.add({staticLabel: "Remove pages after extraction", checkedState:false});
}
}
}
var foutrhrow = dialogRows.add();
with(foutrhrow)
{
var clmn4 = dialogColumns.add();
with(clmn4)
{
var row4 = dialogRows.add();
with(row4)
{
var savebox = checkboxControls.add({staticLabel: "Choose other extraction folder", checkedState:false});
}
}
}
}
}
// If the user made good choices, the script operates.
if(dlg.show()==true)
{
if(pgStart.editValue >= pageinfos()[2] || pgEnd.editValue <= pageinfos()[1])
{
alert("The pages numbers may be at least "+pageinfos()[1] +" for the first page of the range and "+ pageinfos()[2] + " at maximum for the last page");
}
else
{
// If the user choose to pick a different folder, he will be asked for. Otherwise, the dafault folder is the one containing the file.
if(savebox.checkedState==true)
{
var extractfolder = Folder.selectDialog ("Please choose a folder where to save extracted pages...");
if(!extractfolder)
{
exit();
}
else
{
var saveextractfolder = String(extractfolder.fullName)+"/" +String(doc.name).replace (/\.indd/, "");
}
}
else
{
var saveextractfolder = String(pageinfos()[5]);
}
var rem0 = pageinfos()[0]-1;
var rem2 = (pgStart.editValue-2);
// Variables definition regarding to the choice of the user to separate or not the extracted pages.
if(sepbox.checkedState==true)
{
var W = pgEnd.editValue-pgStart.editValue+1;
var rem1 = pgStart.editValue;
}
else
{
var W = 1;
var rem1 = pgEnd.editValue;
}
// Extraction loop
for(w=0; w<W;w++)
{
if(sepbox.checkedState==true)
{
var exportdocname = "_Pg" +(pgStart.editValue+w) +".indd";
}
else
{
var exportdocname = "_Pg"+pgStart.editValue+"_to_Pg_"+pgEnd.editValue +".indd";
}
for(var i=rem0; i>=rem1+w;i--)
{
doc.pages.remove();
}
for(var i=rem2+w; i>=0;i--)
{
doc.pages.remove();
}
var exportdoc = doc.save(File(saveextractfolder + exportdocname));
exportdoc.close(SaveOptions.no);
if(sepbox.checkedState==true && w<(pgEnd.editValue-pgStart.editValue))
{
app.open(File(docfile));
}
}
// If the user chose to remove the extracted pages from the original document, it will re open the first document then remove the unuseful pages.
if(rembox.checkedState == true)
{
app.open(File(docfile));
for(var i=pgEnd.editValue-1; i>=pgStart.editValue-1;i--)
{
doc.pages.remove();
}
app.activeDocument.close(SaveOptions.yes);
}
}
}
}
______________________________
Another option here, post #11:
Copy link to clipboard
Copied
Here's another one to try that works great!!
#targetengine "session";
var myDoc = app.activeDocument;
var myPages = app.activeDocument.pages;
// Create a list of paragraph styles
myStyles = app.activeDocument.allParagraphStyles;
var myarray = [];
for (i = 0; i < myStyles.length; i++) {
myarray.push(get_path(myStyles, myStyles.name));
if (myStyles.parent.constructor.name == "ParagraphStyleGroup") myarray += " [" + myStyles.parent.name + "]";
}
var w = new Window("palette", "Extract Single Page Files ");
app.activate();
w.alignChildren = "left";
// Radio Group 1 ------------------------------------------------------
var byStyle = w.add("group");
byStyle.alignChildren = "left";
byStyle.orientation = "column";
byStyle.margins = [0, 10, 0, 0];
var FontDropdownGroup = byStyle.add("group");
FontDropdownGroup.add("statictext", undefined, "Paragraph Style: ");
var FontDropdown = FontDropdownGroup.add("dropdownlist", undefined, myarray);
FontDropdown.selection = 0;
var grep_group = w.add("group");
grep_group.alignChildren = "right";
grep_group.margins = [0, 10, 0, 5];
grep_group.add("statictext", undefined, "Show 'highlight' Text For File Naming:");
var checkGrep = grep_group.add("button", undefined, "\u2713");
checkGrep.addEventListener("click", function () {
check(checkGrep.text)
});
// Radio Group 2 ------------------------------------------------------
var radio_group2 = w.add("group");
var radioType = radio_group2.add("radiobutton", undefined, "Extract Pages Named By Page#");
// Choose Folder ------------------------------------------------------
var line2 = w.add("panel", [0, 0, 350, 2]);
line2.alignment = 'center';
var folder_group = w.add('group');
folder_group.add("statictext", undefined, "Output Folder: ");
var outfolder = folder_group.add('edittext {characters: 25}');
var pick_button = folder_group.add('iconbutton', undefined, folder_icon(), {
style: 'toolbutton'
});
pick_button.onClick = function () {
var f = Folder(outfolder.text).selectDlg('Choose a folder')
if (f != null) {
outfolder.text = f.fullName + '/';
}
}
outfolder.onDeactivate = function () {
if (outfolder.text !== "" && !Folder(outfolder.text).exists) {
outfolder.text = folder.text += " does not exist";
w.layout.layout();
outfolder.active = true;
} else
if (outfolder.text !== "" && outfolder.text.slice(-1) !== "/") outfolder.text += "/";
}
// Extact Button ------------------------------------------------------
var line = w.add("panel", [0, 0, 0, 0]);
line.alignment = 'center';
var buttonExtract = w.add("button", undefined, "Extract Pages");
buttonExtract.addEventListener("click", function () {
extract(checkGrep.text)
});
buttonExtract.alignment = 'right';
// Radio Event Listeners ------------------------------------------------------
radio_group2.children[0].value = false;
radio_group2.addEventListener("click", function () {
for (var i = 0; i < radio_group2.children.length; i++)
radio_group2.children.value = true;
});
function check(p) {
app.activate();
var FontName = String(FontDropdown.selection);
var doc = app.activeDocument;
try {
highlight_grep(doc, FontName)
} catch (e) {
alert("Please Select the Applied Paragraph Style.")
}
app.documents[0].layoutWindows[0].screenMode = ScreenModeOptions.previewOff;
function highlight_grep(doc, FontName) {
var highlightCondition = check_condition(doc, 'HightlightGrep');
app.findGrepPreferences = app.changeGrepPreferences = null;
if (FontName != "[No Paragraph Style]") {
app.findGrepPreferences.appliedParagraphStyle = String(FontName);
}
app.changeGrepPreferences.appliedConditions = [highlightCondition];
doc.changeGrep();
}
function check_condition(doc, n) {
// Delete condition if it exists
if (doc.conditions.item(n) !== null)
doc.conditions.item(n).remove();
doc.conditions.add({
name: n,
indicatorColor: [225, 225, 255],
indicatorMethod: ConditionIndicatorMethod.useHighlight
});
return doc.conditions.item(n)
}
}
function clear(p) {
app.activate();
var doc = app.activeDocument;
if (doc.conditions.item("HightlightGrep") !== null) {
doc.conditions.item("HightlightGrep").remove();
}
}
// EXTRACTING THE PAGES ------------------------------------------------------
function extract() {
clear();
var myPages = app.activeDocument.pages;
with(myDoc.metadataPreferences) {
}
var FontName = String(FontDropdown.selection);
var myFilePath = outfolder.text;
if (myFilePath !== ""){
}else{
alert ("Please Select a Folder!")
return;
}
// Radio2 ------------------------------------------------------
if (radioType.value === true) {
for (i = 0; i < myPages.length; i++){
var myFolder = (File(String(myFilePath)));
myDoc.saveACopy(File(myFolder+"/Page "+myPages.name+".indd"));
newDoc = app.open(File(myFolder+"/Page "+myPages.name+".indd"), false);
myDoc.pages.duplicate(LocationOptions.AT_END, newDoc.pages[-1]);
newDoc.pages.itemByRange(newDoc.pages[0], newDoc.pages[-2]).remove();
newDoc.close(SaveOptions.YES);
}
}
// StyleOption ------------------------------------------------------
if (radioType.value === false) {
try {
app.findGrepPreferences.appliedParagraphStyle = FontName;
if (FontName == "[No Paragraph Style]")
} catch (e) {
alert("Select a Paragraph Style & Try Again!");
return;}
}
if (radioType.value === false) {
for (i = 0; i < myPages.length; i++) {
var text = [];
var currentPage = myPages;
for (t = 0; t < currentPage.textFrames.length; t++) {
var currentFrame = currentPage.textFrames
app.findGrepPreferences = null;
app.changeGrepPreferences = null;
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = true;
app.findChangeGrepOptions.includeLockedStoriesForFind = true;
app.findChangeGrepOptions.includeMasterPages = true;
app.findGrepPreferences.appliedParagraphStyle = FontName;
var finds = currentFrame.findGrep();
if (finds.length > 0) {
for (var f = 0; f < finds.length; f++) {
text.push(finds
}
}
}
var pageName = String(text.join(', '));
if (pageName === "") {
var pageName = String("NameError" + i);
}
var myFolder = (File(String(myFilePath))); // Create a new file path
myDoc.saveACopy(File(myFolder + "/" + pageName +".indd"));
newDoc = app.open(File(myFolder + "/" + pageName +".indd"), false);
myDoc.pages.duplicate(LocationOptions.AT_END, newDoc.pages[-1]);
newDoc.pages.itemByRange(newDoc.pages[0], newDoc.pages[-2]).remove();
newDoc.close(SaveOptions.YES);
}
app.findGrepPreferences = app.changeGrepPreferences = null;
}
alert("Done Extracting Pages!");
w.close();
}
function get_path(style, style_name) {
while (style.parent.constructor.name != 'Document')
return get_path(style.parent, style.parent.name + ' > ' + style_name);
return style_name;
}
function folder_icon() {
return "\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\x16\x00\x00\x00\x12\b\x06\x00\x00\x00_%.-\x00\x00\x00\tpHYs\x00\x00\x0B\x13\x00\x00\x0B\x13\x01\x00\u009A\u009C\x18\x00\x00\x00\x04gAMA\x00\x00\u00B1\u008E|\u00FBQ\u0093\x00\x00\x00 cHRM\x00\x00z%\x00\x00\u0080\u0083\x00\x00\u00F9\u00FF\x00\x00\u0080\u00E9\x00\x00u0\x00\x00\u00EA`\x00\x00:\u0098\x00\x00\x17o\u0092_\u00C5F\x00\x00\x02\u00DEIDATx\u00DAb\u00FC\u00FF\u00FF?\x03-\x00@\x0011\u00D0\b\x00\x04\x10\u00CD\f\x06\b \x16\x18CFR\x12L\u00CF*\u0092e\u00FE\u00F7\u009F!\u008C\u0097\u008By\x19\u0088\u00FF\u00F7\u00EF\x7F\u0086\u00CF\u00DF\u00FE\u00C6dOz\u00B2\x1C\u00C8\u00FD\x0F\u00C5\x04\x01@\x00\u00A1\u00B8\x18f(##C\u00AD\u009Ak9\u0083\u008E_\x17\u0083i\u00D4<\x06\x16f\u00C6\u009A\t\u00D9\u00D21@%\u00CC@\u00CCH\u008C\u00C1\x00\x01\u00C4\b\u008B<\u0090\u008Bg\x14\u00CAF212,\u00D3q\u00CDb\u00E0\x16Rf`\u00E3\x14f`\u00E5\x14d\u00F8\u00FF\u00E7'\u00C3\u00FE\u00D9a\x18\u009A\u00FF\u00FE\u00FB\u009Fq\u00F3\u00F1\u00CF%\x13\u00D6\u00BE\u00FE\u0086\u00EE\x13\u0080\x00bA\u00B6\x04d\u00A8\u00A1_\x15\u00D8@\u0098\u00A1\u00AC\u00EC\u00FC\f\u00CC<\\\f^\u00A5\u00A7P\f\u00FD\u00F6\u00EE.\u00C3\u00DD\x03\x1D3\u00BE\u00FF<\u00FF\f\u00C8\u00DD\x01\u00C4\x7F\u0090\r\x07\b \x14\u0083A\x04\u00CCP6\x0E!\u0086\u00A3s\x03\x18XY\x19\x19\u00FE\x01\u00C3\x07\x14\u00D6\x7F\u00A1\u00F4\u009F\u00BF\f`\fb\x03}\u00BC\u00A9+U\u0092\u00E1\u00F9\u009B\u00BF\u00BA\u00FD\u00EB_]\u0083\u00C5\x03@\x00\u00B1\u00A0\u00877\u00CC\u00A5\u00F7\x0F\u00F72\u00C8\x1B\x052p\n(\u0080\u00A5\u00FE\u00FD\u00F9\u00C5\u00F0\u00F7\u00F7o\u0086?\u00BF\x7F1\u00FC\u00F9\x05\u00A1\u00FF\u00FE\u00F9\r\u00C6\u009F\u009E_\x00\u00C6\u00C3\u00FDI@\u0085^@\u00FC\x1B\x14J\x00\x01\u00C4\u0084\u00EEb\u0090\u00A1\u00BF>\u00BFd\u00F8\u00FC\u00EA:\x03\u00A7\u00A0\"\u00C3\u00BF\u00BF\u00BF\x19\u00FE\u00FF\u00FD\x034\u00F8\x0F\u00D8\u0090\x7F\u00BFAl \u00FD\u00EF/P\u00EE\x0FX\u00FE\u00C0\u00B1+\f\u008F^\u00FD<\b\u00D4\u00CE\x01\u008B`\u0080\x00\u00C2\b\n\x0E\x1EI\u0086\u009B\u00DB\u00CA\x19\u0084\u0094\u00EC\u0081\u0081\u00CE\u00CA\u00C0\u00C4\x04\u00F4\u00FE\u00AF_`\u0083A\u0086\u0082]\u00F9\x17j8\u0090\u00FE\u00F1\u00E9)\u00C3\u00D6\x13/\x19\u00EE\u00BFa\u00D8\u00C2\u00CE\u00C6\u00CE\n5\u00F8\x0F@\x00ad\u0090W7\u00B60\u00FC\u00FB\u00FF\u0087\u0081KX\x05\u00E8\u00D2\u00DF`\x03\u00FE\u0082]\x0Bq\u00DD\u00BF\u00BF0\u0097\u00FE\x05\u0086\u00EF_\u0086\u00C3G\u008E1\u00DCy\u00FE}9\u00D0\u00D0O\u00C8I\x11 \u00800\f~xr\x06\u0083\u00A0\u00825\u00C3\u00FF\x7FPW\x01\r\x04Y\x00q\u00E9_ \u0086\x1A\x0E\u0094\u00FF\t\f\u00B2\u0095\u00FB\u009F20\u00B3p\u00CC\u0082\u00A6\n\x10\u00FE\x07\u008A<\u0080\x00\u00C20\u0098\u009DO\u0082\u0081\u009DG\x02\x12\u00AE@\u00CD \u0083\u00C0^\x07bP\u00E4\u00FD\u0083\x1A\u00FE\x1F\u00E8\u00ABS'\u008F2\u00DC{\u00FE}\x1D;;\u00C7\x0B\u00A0\u00D6\u009F@\u00FC\x0B\x14q \u0083\x01\x02\u0088\x05\u00C5P6&\u0086\u00F6i\u00DB\x18^\u00BE[\x0FNJ\u00BF\u00FF\u00FCc\x00&\x00\u0086\u00DF\u00BF!l`\x10\x03\u0093\u00D9\x7F0\u00FE\x0B\u00CCX\u00DF\x7F\u00FEe`e\u00E3\u009C\t5\u00F0'\u0092\u008B\x19\x00\x02\b9\u00E7\u0081\x02\u009E\x0B\u0088\u00F9\u00A14+\x119\u00F7\x1F\u00D4\u00D0/P\u00FC\x1Dj8\x03@\x00!\u00BB\u00F8?T\u00F0'\u0096\u00CCC\u00C8\u00E0\u00EFP\u00FA\x1FL\x02 \u0080X\u00D0\x14\u00FD\u0086\u00DA\u00FC\u0083\u00C8\"\x15\u00E6\u0098\u00DF\u00C8\u00C1\x00\x02\x00\x01\x06\x000\u00B2{\u009A\u00B3\x1C#o\x00\x00\x00\x00IEND\u00AEB`\u0082";
}
w.show();
Copy link to clipboard
Copied
Hi,
I've tried this but I got an error message. How do I solve this? I'm using the current version of CC if that's any help.
Copy link to clipboard
Copied
It looks practical but doesn't work on the 2019-2020 version
Copy link to clipboard
Copied
Thank you! This works perfectly. I really appreciate you taking the time to write out the comments as well. I'm going to read through it all and try and really get a good understanding.
Copy link to clipboard
Copied
I can’t take any credit for commenting the script, like all helpful script authors do, Loïc Aigon documented the script.
Copy link to clipboard
Copied
hi, how do i find this script or save it out? I know stupid question, but forgive me, i'm old
Copy link to clipboard
Copied
On a Mac copy the code in to TextEdit, then choose Format->Make Plain Text before saving. Save the file naming to your liking then add the .jsx file extension. In InDesign go to (Window > Utilities > Scripts), then right-click on User folder, Reveal in Finder and place the script in the Scripts Panel folder. You'll now be able to run the script from the Scripts panel user folder by double clicking on it.
Regards,
Mike
Copy link to clipboard
Copied
hi, how do i find this script or save it out? I know stupid question, but forgive me, i'm old