Copy link to clipboard
Copied
I am converting a print indesign file for use with dps. The problem is DPS wants individual files for each page. Is there a script to take each page and save as an indesign file?
G'day
You could start with something like this :
...
tell application "Adobe InDesign CS4"
set enable redraw of script preferences to false
activate
set dsDoc to active document
set dsDocProps to properties of document preferences of dsDoc
set pages per document of dsDocProps to 1
set dsFilePath to (full name of dsDoc) as text
set text item delimiters of AppleScript to "."
set dsFilePath to text 1 thru text item -2 of dsFilePath
set text item delimiters of AppleScript to ""
Copy link to clipboard
Copied
Yes. Our fellow scripter wrote a script for this, please check this site more details....
http://www.loicaigon.com/en/auto.php?goTo=2
Thanks,
Green4ever
Copy link to clipboard
Copied
Is there one for cs 5.5?
Copy link to clipboard
Copied
I've downloaded the file that Green4ever suggested, but it doesn't seem compatible with CS5.5.Does any one happen to know if something in the script can be altered so this works on CS5.5?
Thanks -
Copy link to clipboard
Copied
you can try this....
//**************************************************************************************************************
//**************************************************************************************************************
//****
//**** Page extractor 1.0 - A script from Loïc Aigon with the great help of Peter Kahrel and other guys
//**** that cooperated on this stuff in tha adobe scripting forum. Feel free to improve.
//**** a little mail at loic _ aigon@yahoo.fr if you appreciate that script would be nice.
//****
//**************************************************************************************************************
//**************************************************************************************************************
//======================================
// <L10N> :: FRENCH_LOCALE :: RUSSIAN_LOCALE
//======================================
// Please save you file first before processing the script :: Enregistrez votre document avant de lancer le script :: Пожалуйста сохраните документ перед запуском скрипта
// Extract pages... :: Extraire des pages... :: Извлечь страницы...
// to :: a :: по
// Extract as separate pages :: Extraire chaque page comme un fichier :: Извлечь как отдельные страницы
// Remove pages after extraction :: Supprimer les pages après extraction :: Удалить страницы после извлечения
// Choose other extraction folder :: Choisir un autre dossier d'extraction :: Выбрать папку для сохранения
// </L10N> ::
// 2. Add the code's block below in your script:
if ( typeof __ == 'undefined' )
{
__sep = ' :: ';
__beg = ' <L10N>';
__end = ' </L10N>';
/*arr*/File.prototype.getCommentsContaining = function(/*str*/k_)
//--------------------------------------
{
var r = [];
if ( this.open('r') )
{
var line;
while(!this.eof)
{
line = this.readln();
if ( ( line.substr(0,2) == '//' )
&& ( line.indexOf(k_) >= 0 ) )
r.push(line.substr(2));
}
this.close();
}
return(r);
}
/*arr*/Array.prototype.parseL10N = function(/*str*/locale_)
//--------------------------------------
{
var r = [];
var sz = this.length;
var lm, ss;
var st = -1
var rg = 0;
for ( var i=0 ; i < sz ; i++ )
{
ss = this.split(__sep, lm);
if ( ( st == -1 ) && ( ss[0] == __beg ) )
{
lm = ss.length;
for ( var j = 1 ; j < lm ; j++ )
if ( ss
== locale_ ) rg=j; st = 0;
continue;
}
if ( st == 0 )
{
if ( ( rg == 0 ) || ( ss[0] == __end ) ) break;
if ( ss.length <= rg ) continue;
r[ss[0].substr(1)] = ss[rg];
}
}
return(r);
}
/*str*/Object.prototype.toLocaleName = function()
//--------------------------------------
{
for ( var p in Locale )
if ( Locale
== this ) return(p);
return(null);
}
String.L10N = File(app.activeScript).
getCommentsContaining(__sep).
parseL10N(app.locale.toLocaleName());
function __(s){return(String.L10N
||s);}}
// 1. Control for documents open. If true, the script launches the dialog
if(app.documents.length >0)
{
var doc = app.activeDocument;
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.0 - ©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);
}
}
}
}
Note: I have not tested all the features of this script.
Copy link to clipboard
Copied
Hi all,
I think the answer is here :
http://indesignsecrets.com/get-your-old-scripts-running-again-with-make-it-run.php
Best,
Loic
Copy link to clipboard
Copied
Thanks! Well, it's almost working, I think. I used the new script that Green4ever posted above this last comment and created a new .jsx document. I loaded it into Indesign CS 5.5 and then ran the make-it-run script suggested above (it doesn't work at all without using the make-it-run script). Here's what happens:
It extracts one page (even though I set it for all 12 of my pages to make individual pages) and then gives me an error saying:
ReferenceError: Object is invalid
I'm not sure what this means or how to fix it. Does anyone else?
Continued thanks -
best,
Drew
Copy link to clipboard
Copied
Hi drewford,
I think you should convert the original old script by loic.
The makeitrun-script makes a separate script that instructs INDCS5.5 how to run the old script.
Works flawlessly for me..
Copy link to clipboard
Copied
Hi,
I am attempting to use the extract pages script in InDesign CS6. I ran the "Make it run" script to update the extract pages script and then attempt to run the new script on the 64 page document. I am gettign the following error message: "Error: no file is associated with the currently active script." Does anyone have a suggestion?
Thanks,
Paul
Copy link to clipboard
Copied
Did you ran the script from ESTK? Try running it from scripts panel.
Copy link to clipboard
Copied
@ Green4ever - that's interesting you suggest that as I've been wondering why that seems to make a difference in some cases and not in others. Please elaborate if you're able as to why a script will run flawlessly from the InDesign Scripts panel but gets all constipated in ESTK?
Copy link to clipboard
Copied
Thanks for the response - am just now getting back to this. Loic's site is down as luck would have it. Is it at all possible to post the script (here in this thread) that is working for you in CS5.5?
best,
Drew
Copy link to clipboard
Copied
G'day Drew
What is it that you're trying to do that doesn't work with the script I posted?
It might be possible to adapt that script to your needs.
m.
Copy link to clipboard
Copied
Hi -
Thanks for the response. Full disclosure: I don't code. Maybe this is a simple fix... I just don't know.
I'd love for the script to be able to separate out each InDesign page in a file (and in a perfect world, allow me to rename each one it separates out, since my client is very particular about how files are named... but the splitting out is primary goal for now).
When I create a new jsx file with the code you posted I get this error message:
Error Number: 25
Error String: Expected: ;
Engine: main
File: /Applicaitons/Adobe Indesign CS5.5/Scripts/Scripts Panel/Samples/JavaScript/dwayne_Smith.jsx [I obviously named the script after you ha]
Line: 1
Source: tell application "Adobe InDesign CS5.5"
Offending Text: application
I'm not sure where to go from there. I don't have enough perspective in Code Land to understand why the things I try to do to fix it don't work - like taking out the word "application" or other uninformed things)
Thanks for any help you can provide
best,
Drew
Copy link to clipboard
Copied
OK — the script I posted is Applescript, not Javascript — so it's only useful if you're on a Mac.
Copy and paste it into AppleScript Editor which you'll find in Appications > Utilities (in older versions of OSX it's called Script Editor and it's in a different folder in Applications)
Change the first line to :
tell application "Adobe InDesign CS5.5"
and change the 8th line to :
set dsFilePath to (full name of dsDoc) as string
you might also want to delete this line :
close dsDoc saving no
You can run it directly from the editor by hitting the green run button at the top (this will help you identify any issues yet to be resolved)
Once you're happy with the way it runs, save it as a script (.scpt) into your Scripts Panel folder (will be somewhere like Applications > Adobe InDesign CS5.5 > Scripts > Scripts Panel)
Then it will be available in your Scripts Panel in InDesign (double click to run)
m.
Copy link to clipboard
Copied
I should say — this is the barest minimum for this kind of task.
It just takes a multi-page document and splits it into separate single-page documents
So, BizCard.indd becomes BizCard_1.indd, BizCard_2.indd, etc.
These are saved in the same location as the original.
In its current form it doesn't :
allow user to choose the new document names;
allow user to choose a different location for new files;
take into account InDesign's ability to have various page sizes;
etc.
Very basic functionality.
m.
Copy link to clipboard
Copied
Whoa - that was it!
I did have to take the semicolon out from the end of the script, because I got an error message - and now it works! I really appreciate your help! This will definitely save me some time.
If only I could figure out how to be able to stop the script before it each time it names a file (so that I can name it myself) that would be amazing. I'll research a little on that and see what I might can do.
Can't thank you enough
Drew
Copy link to clipboard
Copied
Glad it got you at least part way there.
Have a look at this post — it gives an example of how to build a dialog for user input in InDesign : http://macgrunt.com/2011/11/26/indesign-scripting-lesson-11/
Have fun with it.
m.
Copy link to clipboard
Copied
Is there any chance that someone can point me to a script that would work for a Windows machine?
Copy link to clipboard
Copied
this may help:
Copy link to clipboard
Copied
You may also want to read the section:
About scripting languages
in
ADOBE INDESIGN CS6
SCRIPTING TUTORIAL
Requesting a script for "Windows" is rather unclear, but it will either be a JavaScript or a Visual Basic script; VBScript and
"Translating a script from one
language to another is fairly easy."
Copy link to clipboard
Copied
Can your script be edited easily to change the number of pages you can split into? Two pages is what I would use frequently, but I would like to figure out where to edit the script in case I need my file split differently. I am a total script novice, so excuse my lack of knowledge.
And thank you for sharing yours!
jm
Copy link to clipboard
Copied
g'day jm
to separate out in sets of two you could change it to this :
tell application id "com.adobe.InDesign"
set enable redraw of script preferences to false
activate
set dsDoc to active document
set dsDocProps to properties of document preferences of dsDoc
set pages per document of dsDocProps to 1
if page width of dsDocProps > page height of dsDocProps then
set page orientation of dsDocProps to landscape
else
set page orientation of dsDocProps to portrait
end if
set dsFilePath to (full name of dsDoc) as string
set text item delimiters of AppleScript to "."
set dsFilePath to text 1 thru text item -2 of dsFilePath
set text item delimiters of AppleScript to ""
set dsPageCount to (count of pages of dsDoc)
repeat with w from 1 to dsPageCount by 2
set dsNewDoc to make new document with properties {document preferences:dsDocProps}
duplicate page w of dsDoc to after page -1 of dsNewDoc
duplicate page (w + 1) of dsDoc to after page -1 of dsNewDoc
set active document to dsNewDoc
delete page 1 of dsNewDoc
save dsNewDoc to (dsFilePath & "_" & w & ".indd")
close active document
delay 1
end repeat
end tell
i had to add that new if statement because I noticed that CS6 was not getting the page orientation right.
the other changes are to the repeat loop – it now increments by 2 and has an additional duplicate page line.
the after page command has also been changed to '-1'. page -1 is the last page of the document, irrespective of how many pages there are.
(all this should give you a bit of an idea of how you can adapt existing scripts to your specific needs).
if you wanted something more adaptable to various page ranges – or even multiple page ranges from the same document – you'd need to start playing around with user interfaces.
you can see how i used such an approach to exporting pdfs here : http://macgrunt.com/2011/11/26/indesign-scripting-lesson-11/
hope that gets you started on a long and rewarding relationship with scripting
m.
Copy link to clipboard
Copied
Thanks, myDwayneSmith. The script works quite nicely, especially since I am not a script writer. I wanted to put my images on separate pages in an ebook, to force the page break. BUT the resulting files each have the Pages Numbering and Section Options set to "Start Page Numbering at NN" ( where NN is the page number of the first page in the original section). So when the files are gathered into a book, all the new files have the same page number. The orginal file has the Automatic Page Numbering set, so not sure why this option gets changed. I can simply open each file and change the Page Numbering option, but it would be nice not to have to do that. Running 5.5. Any ideas?
Copy link to clipboard
Copied
G'day
I assume you're using the book feature in InDesign to recompile the pages into one document (?).
In which case you should be able to 'Update Numbering' from the book panel dropdown menu.
(although I would expect this to happen by default when you first add the documents to the book)
d.