Created
June 21, 2012 09:23
-
-
Save bastien/2964807 to your computer and use it in GitHub Desktop.
Extracting a page from an InDesign document (2 different approaches)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var doc = app.activeDocument; | |
if(doc.saved == true) | |
{ | |
extract(2); | |
} | |
else | |
{ | |
alert("Save you file."); | |
} | |
function extract(pagePosition){ | |
var docpath = doc.fullName; | |
for(var i=doc.pages.length; i>pagePosition;i--) | |
{ | |
doc.pages[i-1].remove(); | |
} | |
for(var i=pagePosition-1; i>=1;i--) | |
{ | |
doc.pages[i-1].remove(); | |
} | |
var exportdoc = doc.save(File('~/test_extract.indd')); | |
exportdoc.close(SaveOptions.no); | |
app.open(File(docpath)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var doc = app.activeDocument; | |
if(doc.saved == true) | |
{ | |
extract(2); | |
} | |
else | |
{ | |
alert("Save you file."); | |
} | |
function extract(pagePosition){ | |
var exportDoc = app.documents.add(false); | |
var page = doc.pages.item(pagePosition-1) | |
page.duplicate(LocationOptions.BEFORE, exportDoc.pages.firstItem()); | |
exportDoc.pages.lastItem().remove(); | |
exportDoc.save(File('~/test_extract_2.indd')); | |
exportDoc.close(SaveOptions.no); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@bastien: Many thanks! This script is very helpful. Especially method 2 is very fast (and less intrusive than method 1).
For extracting all pages into a folder (plus progressbar from https://gist.github.com/kuyseng/2792080):