Extracting pages as a separate indesign document ?

Engaged ,
Jun 12, 2019

Copy link to clipboard

Copied

How can I extract few pages as a separate indesign document from a large document?

For example if I have a 300 page document and I want to extract page 21-50, currently I save the document as a separate file, delete pages 1-20 and 51-300, then save it as a separate indesign file containing only my 21-50 pages. Or another longer way is to create a new document with same pages size and margin settings, move the required pages to it and save it.

Is there a faster way to directly extract page 21-50 as a separate InDesign document?

InDesign version - CC 2019

Windows version - Windows 10 (ver. 1903)

TOPICS
Scripting

Views

4.4K

Likes

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

Extracting pages as a separate indesign document ?

Engaged ,
Jun 12, 2019

Copy link to clipboard

Copied

How can I extract few pages as a separate indesign document from a large document?

For example if I have a 300 page document and I want to extract page 21-50, currently I save the document as a separate file, delete pages 1-20 and 51-300, then save it as a separate indesign file containing only my 21-50 pages. Or another longer way is to create a new document with same pages size and margin settings, move the required pages to it and save it.

Is there a faster way to directly extract page 21-50 as a separate InDesign document?

InDesign version - CC 2019

Windows version - Windows 10 (ver. 1903)

TOPICS
Scripting

Views

4.4K

Likes

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
Jun 12, 2019 0
Adobe Community Professional ,
Jun 12, 2019

Copy link to clipboard

Copied

As far as I know there is no built-in way to do it faster than you've already found.

You might inquire in the InDesign Scripting forum to see if anyone has written a script to do it faster.

InDesign Scripting

Likes

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
Reply
Loading...
Jun 12, 2019 1
Adobe Employee ,
Jun 12, 2019

Copy link to clipboard

Copied

Hi Arjun,

Thanks for reaching out. As Steve said, there is no other method that could help you to create a new file with specific pages. I will move this discussion to InDesign Scripting​ forums so that you can get some help from our scripting experts.

If you want you can also raise this feature request here: Adobe InDesign Feedback.​ This is the best way of communicating with the Engineering and Product Management teams regarding issues and suggestions so they can be implemented in future releases.

Regards,

Srishti

Likes

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
Reply
Loading...
Jun 12, 2019 0
Adobe Community Professional ,
Jun 12, 2019

Copy link to clipboard

Copied

Hi Arjun,

Try the following code, it will ask for a prompt to enter the pages you want to delete. You can enter a range as - separated number, multiple entries are separated by a ,

For ex to delete pages 1 and 6 and 8 to 10 use the string 1,6,8-10

The script will also prompt for the save location of the new file, browse the location and key in the filename

function pages_remove(number_pages)

{

    range_test = number_pages.replace(/(\d+)-(\d+)/g, function(a,b,c) { a = b; b = Number(b); c = Number(c); for (b++; b<=c; b++) a+=','+b; return a}).split(",");

    var pg = app.activeDocument.pages.everyItem().getElements()

    for (i=0; i<range_test.length; i++)

    {

          pg[parseInt(range_test) - 1].remove();

    }

}

var pgRange = Window.prompt("Enter the page Range")

if(pgRange)

{

    var f = new File("~/Desktop")

    var fl = f.saveDlg("Save As")

    if(fl)

          app.doScript('pages_remove(pgRange)', ScriptLanguage.JAVASCRIPT, null, UndoModes.ENTIRE_SCRIPT)

    app.documents[0].saveACopy(fl)

    app.documents[0].undo()

}

-Manan

Likes

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
Reply
Loading...
Jun 12, 2019 2
Enthusiast ,
Jun 14, 2019

Copy link to clipboard

Copied

Hello Arjun,

you should give the script from Extract pages a try the original script written by Eddy and Loic Aigon was modified by

Kasyan Servetsky.

It works fine on a Mac InDesign - CC 2019, I don't have any way to test on Windows version - Windows 10.

// 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);

            }

        }

    }

}

Regards,

Mike

Likes

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
Reply
Loading...
Jun 14, 2019 0
New Here ,
Jan 29, 2020

Copy link to clipboard

Copied

I tried the script and get the error # 24 "Error string: doc.pages.remove is not a function" Is there an easy way to edit the code myself and fix that?

Likes

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
Reply
Loading...
Jan 29, 2020 0
Adobe Community Professional ,
Jan 29, 2020

Copy link to clipboard

Copied

Hi Rachael,

this is, again!, one of the examples where script code was damaged when moving an old thread to this new forum.

There are several for-loops with an iterator variable named i. Inside the loop that variable is missing. Was deleted in the process of moving threads around.

 

This for example:

 

for(var i=rem0; i>=rem1+w;i--)
{
doc.pages.remove();
}

 

 

should be:

 

for(var i=rem0; i>=rem1+w;i--)
{
doc.pages[i].remove();
}

 

 

There are other spots in the code where this happens.
And that's only one issue I can see at first glance. There may be even more.

 

Let's see if I can find the original code on Kasyan's new domain.

Ah. That should be the one:

http://kasyan.ho.ua/indesign/all/extractpages.html

 

Regards,
Uwe Laubender

( ACP )

 

 

 

Likes

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
Reply
Loading...
Jan 29, 2020 1