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)
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.
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
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
Copy link to clipboard
Copied
Hy @Manan Joshi and @Laubender , I tried this code presented by @Manan Joshi above, and it's displayed an error when I used page range of 1-495,1028-1526 in a document of 1527 pages.
This is the error
However, when I tried to remove from page 500 and above using 500- in the prompt window, it worked fine and fast.
Copy link to clipboard
Copied
Please anyone who's online and can should kindly help me with the above problem.
Copy link to clipboard
Copied
I can see issues in the code posted on this thread, most probably due to forum software migration. Try the code given below
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[i]) - 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
Copy link to clipboard
Copied
Manan,
FWIW: you should be able to edit your own post from Jun 12, 2019.
And yes, it's a drag with all those scripts that were damaged by moving the threads from the old forum to this new one by the end of 2019.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Thanks for pointing that Uwe, I do know that but did not edit it as in the past some members of the community did not like me making edits to the posted code and pointed that out to me. In order to quell down the disagreement of such opinions I generally avoid editing posts especially if it is a code snippet.
-Manan
Copy link to clipboard
Copied
@Manan Joshi I tried the second script code, it worked fine, no errors, but extremely slow, maybe because I input multiple pages range (i.e. 1-495,1026-1057), I really don't know. However, the first script was very fast, except for the error as explained earlier, though I input single instructions (I.e. 500-).
It was very slow that I noticed how it delete pages one by one.
Can you please recommend other ways apart from InDesign move pages?
Please
Copy link to clipboard
Copied
I discussed this issue in another thread to get comments from fellow scripters and the conclusion we came to is that the method we use to remove pages does get slow with big documents. So I would suggest maybe you could split your document into smaller documents and then use the script. You can read the discussion at the following link
-Manan
Copy link to clipboard
Copied
Hi Jameel,
did you try Kasyan's script I linked to?
http://kasyan.ho.ua/indesign/all/extractpages.html
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
@Laubender Yes, I did, but it's very slow, similar to the normal InDesign move pages. Can you please recommend other methods?
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
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?
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 )
Copy link to clipboard
Copied
Kaysan's modified script works on ID 17.1. I'm able to extract individual pages as separate .INDD files, however, the pages don't retain the page number assigned to them in the original document. Each file is named (_Pg1, _Pg2, _Pg3, etc.), but the Start Page # on each is 1, which makes the display number for each page 1.
If anyone can think of a better way to create blank pages, one page per .INDD file, each with its own unique start page (1, 2, 3, 4, 5, etc.) I would be most thankful.
I figured the easiest way would be to have one . INDD file containing the correct document setup, all the blank pages (with numbered footers) saved, then extract the pages into files from there. That's why I'm here and it sounds like others would be interested in the same workflow. Between four magazines, a script would save several hours of effort.
Copy link to clipboard
Copied
Would it not work to simply create a desitnation document, and then, in the pages panel, right click on the selected page range and say "Move Pages" and choose the new document as the destiation document?
Copy link to clipboard
Copied
Yes, Quinn, that’s a great method and one I’ve used several times. It helps to have saved and named the exact blank document preset so creating the new document with the same page setup is one click.
Copy link to clipboard
Copied
FYI – using Move Pages, you need to have both the source and the destination documents open.
Also, if you need to maintain all of the document specs, you could duplicate the original large file, delete all text and pages, save it as a 'blank template' then use it for each extraction.
Copy link to clipboard
Copied
Hi quinnrrw,
this thread started either in the old InDesign Scripting forum or, if it started in the old InDesign forum, the question clearly is tagged as a scripting question.
Now to your suggestion:
To simply do a new document and move pages over will not help much, because there are so many things text in a different document would rely upon: baseline grid, special paragraph styles, character styles, object styles etc.pp. All that could conflict with the styles or settings of a new document.
So the best way is really to work with the original document only.
Arjun mentioned one example:
You start out with a 300 pages document.
You want to "extract" pages 21-50.
To give a bit of code. The first step would be to set the number of pages to 50.
This can be done very efficiently without looping pages:
app.documents[0].documentPreferences.pagesPerDocument = 50 ;
We also could take a slighty different approach:
[1] Duplicate document A to document B.
[2] Set the number of pages of doc B to 1.
[3] Duplicate a range of pages from doc A to doc B before the first page.
[4] Make sure that the startpage number is the right one.
[5] Remove the last page.
Save.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Yes, make a new doc same size as original, the select the pages in the pages panel you require, right click and move pages to new doc. Done