Copy link to clipboard
Copied
Hi Team,
When the script creates the full set of pages, each page is correctly labeled with the proper section and page number. (A1, B6, etc.), with the proper info in the folio.
However, when the pages are split into individual pages, each page is now labeled as A1. Each page is considered the “first” page.
Code:
function Split(fileName, path, embed, useName) {
var tempFile = File(Folder.temp + "/" + ".indd");
// return;
// loop over all pages
for (i = 0; i < doc.pages.length; i++) {
// update the progress bar
statictext1.text = (i + 1) + " of " + doc.pages.length;
palette.update();
bar.value++;
// saveACopy the doc as a temporary doc
var page = doc.pages[i];
var finalFile = File(Folder(path) + "/" + GetPageFileName(doc, useName, page));
//$.writeln(" file = "+ finalFile);
doc.saveACopy(tempFile);
// open the temp doc
tempDoc = app.open(tempFile);
// remove all papages except one.
for (var j = tempDoc.pages.length - 1; j >= 0; j--) {
if (tempDoc.pages[j].id != page.id) {
tempDoc.pages[j].remove();
} else {
// $.writeln("not removing " + tempDoc.pages[j].name);
}
}
// at this point, the temp doc contains a single page.
//////do we want to embed the graphics?
if (embed == true) {
for (k = 0; k < tempDoc.allGraphics.length; k++) {
tempDoc.allGraphics[k].itemLink.unlink();
}
}
// save to the destenation file and close the temp file.
tempDoc.saveACopy(finalFile);
tempDoc.close(SaveOptions.NO);
} // next page
palette.close();
} else {
alert("The path is not valid:\n" + path);
}
}
//Function used to get the page name
function GetPageFileName(doc, usePlanName, page) {
if (usePlanName) {
var name = page.extractLabel("pageName");
//var pageNumber = page.extractLabel("pageName");
if (name == "") {
name = "missing name-" + page.name;
}
return name + ".indd";
} else if (app.documents.length != 0) {
var pub = doc.extractLabel("product");
var date = doc.extractLabel("issueDate");
var zone = doc.extractLabel("zone");
// var zone = doc.extractLabel("head_zone");
return pub + "-" + zone + "-" + date + "-" + page.name + ".indd";
} else {
return "error: no file open.indd"
}
}
Copy link to clipboard
Copied
Is this just a code snippet? I get syntax errors when trying to run it, an else without an if and there's a loader palette that is trying to update that isn't there. Doc isn't defined etc.
It sounds like what you're looking for is something like this if you're creating a new section:
doc = app.activeDocument;
section = doc.sections.add(doc.pages[1],pageNumberStart:8,continueNumbering:false,sectionPrefix:"A",includeSectionPrefix:true})
Or this if you're editing the default section that starts at page 1:
doc = app.activeDocument;
doc.sections[0].properties = {pageNumberStart:8,continueNumbering:false,sectionPrefix:"A",includeSectionPrefix:true};
}