Friday, 30 January 2015

Basic Document Management Adobe InDesign Script

Create
New document
var myDocument = app.documents.add();

Creates a new document using the specified document preset
var myDocument = app.documents.add(true,app.documentPresets.item("myDocumentPreset"));

Creates a new document without showing the document window.
//The first parameter (showingWindow) controls the visibility of the
//document. Hidden documents are not minimized, and will not appear until
//you add a new window to the document.
var myDocument = app.documents.add(false);
//To show the window:
var myWindow = myDocument.windows.add();

Open
OpenDocument.
app.open(File("/c/myTestDocument.indd"));

Opens an existing document in the background,
var myDocument = app.open(File("/c/myTestDocument.indd"), false);

When you want to show the hidden document, create a new window.
var myLayoutWindow = myDocument.windows.add();

Save
If the active document has been changed since it was last saved, save it.
if(app.activeDocument.modified == true){
      app.activeDocument.save();
}

If the active document has not been saved (ever), save it.
if(app.activeDocument.saved == false){
      //If you do not provide a file name, InDesign displays the Save dialog box.
      app.activeDocument.save(new File("/c/myTestDocument.indd"));
}

Save the active document as a template.
var myFileName;
if(app.activeDocument.saved == true){
      //Convert the file name to a string.
      myFileName = app.activeDocument.fullName + "";
      //If the file name contains the extension ".indd", change it to ".indt".
      if(myFileName.indexOf(".indd")!=-1){
            var myRegularExpression = /.indd/gi
            myFileName = myFileName.replace(myRegularExpression, ".indt");
      }
}
//If the document has not been saved, then give it a default file name/file path.
else{
myFileName = "/c/myTestDocument.indt";
}
app.activeDocument.save(File(myFileName), true);

Close
CloseDocument
app.activeDocument.close();
//Note that you could also use:
//app.documents.item(0).close();

Close document with saving
//Use SaveOptions.yes to save the document,SaveOptions.no to close the
//document without saving, or SaveOptions.ask to display a prompt. If
//you use SaveOptions.yes, you'll need to provide a reference to a file
//to save to in the second parameter (SavingIn).
//Note that the file path is provided using the JavaScript URI form
//rather than the platform-specific form.
//If the file has not been saved, display a prompt.
if(app.activeDocument.saved != true)
{
      app.activeDocument.close(SaveOptions.ask);
      //Or, to save to a specific file name:
      //var myFile = File("/c/myTestDocument.indd");
      //app.activeDocument.close(SaveOptions.yes, myFile);
}
Else
{
      //If the file has already been saved, save it.
      app.activeDocument.close(SaveOptions.yes);
}

Close all open documents without saving
for(myCounter = app.documents.length; myCounter > 0; myCounter--){
      app.documents.item(myCounter-1).close(SaveOptions.no);
}

5 comments:

  1. I use Ideals virtual data room for my company documents system management. I think it is one of the most useful services for companies, which want to save time and money./

    ReplyDelete
  2. I have experience when I first started my blog.I’m happy that I came across with your site this article is on point,thanks again and have a great day.
    Document Management Software Dubai
    Document Management Software
    Document Management Software UAE

    ReplyDelete
  3. Hi, I want a script to open the document when we are not saving the document

    ReplyDelete
  4. All of these tips are great, that’s very interesting. I’m so tempted to try that myself, but you would think if it were effective, more people would do it.
    Document Management Software India
    Document Management Software Chennai
    Document Management Software
    Electronic Document Management System

    ReplyDelete
  5. Hi everyone,

    I need a syntax to rename the opened document to closed document.

    ReplyDelete