• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Splitting up Indesign documnet into individual pages.

New Here ,
Jan 27, 2023 Jan 27, 2023

Copy link to clipboard

Copied

Hi

I am trying to splits up an InDesign document into individual pages and is not correctly naming pages (each page is considered the “first” page).

every page is consider as first pages please see the attachment below 

also code for the same is posted below

 

function Split(fileName, path, embed, usePlanName) {
// test for valid path
var savePath = Folder(path);
if (savePath.exists == true) {

var doc = app.activeDocument;

// Create the save path if it down't exist.
if (Folder(path).exists == false) {
Folder(path).create();
}

// if the script crashed, then the temp file may be present whoch crashes the script
for (var i = 0; i < app.documents.length; i++) {
if (app.documents[i].name == "NavigaPlanTemp.indd") {
alert("NavigaPlanTemp.indd cannot be split. Please close this document and try again");
return;
}
}

// create the progress bar
var palette = new Window("palette", undefined, undefined, {
closeButton: false
});
palette.text = "Splitting Files";
palette.preferredSize.width = 250;
palette.orientation = "column";
palette.alignChildren = ["center", "top"];
palette.spacing = 10;
palette.margins = 16;

var statictext1 = palette.add("statictext", undefined, undefined, {
name: "statictext1"
});
statictext1.text = "1 of XXXX";
var bar = palette.add("progressbar", undefined, 0, doc.pages.length);
bar.preferredSize.width = 250;
palette.show();

// the temporty file is repeatibly save-as, opened and closed.
var tempFile = File(Folder.temp + "/" + "new.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, usePlanName, 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);
}
}

 

 

 

Also GetPageFileName function is defined as below.

function GetPageFileName(doc, usePlanName, page) {
if (usePlanName) {
var name = 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"
}
}

 

Please help with the correction in code ,why we are getting every page number as "1"

Thanks in advance

TOPICS
Bug , Performance , Scripting , UXP Scripting

Views

300

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 27, 2023 Jan 27, 2023

If your page naming uses lettering rather than numbers, it will fail. To get the number relative to the total doc page count you could do: 

tempDoc.sections[0].pageNumberStart = page.documentOffset + 1;

Votes

Translate

Translate
Community Expert ,
Jan 27, 2023 Jan 27, 2023

Copy link to clipboard

Copied

If I understand the problem, you need to set the copied page's name to the page number you want in this snippet:

for (var j = tempDoc.pages.length - 1; j >= 0; j--) {
    if (tempDoc.pages[j].id != page.id) {
        tempDoc.pages[j].remove();
    }
    //change the name of the target doc page here
    tempDoc.pages[0].name = page.name;
}

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 27, 2023 Jan 27, 2023

Copy link to clipboard

Copied

@brianp311 

getting error "name is read only property" after implememting this 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2023 Jan 27, 2023

Copy link to clipboard

Copied

Oh right, how's this?

for (var j = tempDoc.pages.length - 1; j >= 0; j--) {
    if (tempDoc.pages[j].id != page.id) {
        tempDoc.pages[j].remove();
    }
}
tempDoc.sections[0].continueNumbering = false;
tempDoc.sections[0].pageNumberStart = Number(page.name);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 27, 2023 Jan 27, 2023

Copy link to clipboard

Copied

thanks for being so quick but still getting 

 

error like

inavlid value for set property "pageNumberstart" Epected long integer (1-9999) but received NaN

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2023 Jan 27, 2023

Copy link to clipboard

Copied

If your page naming uses lettering rather than numbers, it will fail. To get the number relative to the total doc page count you could do: 

tempDoc.sections[0].pageNumberStart = page.documentOffset + 1;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 11, 2023 Feb 11, 2023

Copy link to clipboard

Copied

LATEST

@brianp311 Hi ,

have implemented this approch nd is working fine with template having continuos numbering ...but what if  the page number of the InDesign document starts at page 1 and that there are no gaps or jumps in the page number. We can have document which start with page 8 and has a jump from pages 11 to 17, 

is the approch is same  or we have something generic with hold true in both conditions.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines