Macromedia InDesign - CS6 Server User Guide

ADOBE® INDESIGN® CS6
ADOBE INDESIGN CS6 SERVER
SCRIPTING GUIDE
2012 Adobe Systems Incorporated. All rights reserved.
Document Update Status
CS5.5 Minor edits Content not guaranteed to be current.
Adobe® InDesign® CS6 Server Scripting Guide
The content of this guide is furnished for informational use only, is subject to change without notice, and should not be construed as a commitment by Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability for any errors or inaccuracies that may appear in the informational content contained in this guide.
Please remember that existing artwork or images that you may want to include in your project may be protected under copyright law. The unauthorized incorporation of such material into your new work could be a violation of the rights of the copyright owner. Please be sure to obtain any permission required from the copyright owner.
Any references to company names in sample templates are for demonstration purposes only and are not intended to refer to any actual organization.
Adobe, the Adobe logo, Adobe Bridge, Creative Suite, InCopy, InDesign, Reader, and Version Cue are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries. Microsoft and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Macintosh and Mac OS are trademarks of Apple Computer, Incorporated, registered in the United States and other countries. All other trademarks are the property of their respective owners.
Adobe Systems Incorporated, 345 Park Avenue, San Jose, California 95110, USA. Notice to U.S. Government End Users. The Software and Documentation are “Commercial Items,” as that term is defined at 48 C.F.R. §2.101, consisting of “Commercial Computer Software” and “Commercial Computer Software Documentation,” as such terms are used in 48 C.F.R. §12.212 or 48 C.F.R. §227.7202, as applicable. Consistent with 48 C.F.R. §12.212 or 48 C.F.R. §§227.7202-1 through
227.7202-4, as applicable, the Commercial Computer Software and Commercial Computer Software Documentation are being licensed to U.S. Government end users (a) only as Commercial Items and (b) with only those rights as are granted to all other end users pursuant to the terms and conditions herein. Unpublished-rights reserved under the copyright laws of the United States. Adobe Systems Incorporated, 345 Park Avenue, San Jose, CA 95110-2704, USA. For U.S. Government End Users, Adobe agrees to comply with all applicable equal opportunity laws including, if appropriate, the provisions of Executive Order 11246, as amended, Section 402 of the Vietnam Era Veterans Readjustment Assistance Act of 1974 (38 USC 4212), and Section 503 of the Rehabilitation Act of 1973, as amended, and the regulations at 41 CFR Parts 60-1 through 60-60, 60-250, and 60-741. The affirmative action clause and regulations contained in the preceding sentence shall be incorporated by reference.
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Intended audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
For more information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
What you need for InDesign Server scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Using Scripts from this Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Other JavaScript development options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
InDesign and InDesign Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Your first InDesign Server script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Adding features to “Hello World” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
A simple script for running scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Converting an InDesign script to InDesign Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3 Constructing a Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Setting up measurement units and master spread margins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Adding a baseline grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Adding master page items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Adding master text frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Overriding master page items and adding text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Adding and applying a paragraph style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Placing a text file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Placing a graphic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4 Middle Eastern Scripting Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Setting up a document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Working with text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Setting paragraph attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Setting character attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Using styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Working with tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3
1

Introduction

Adobe® InDesign® Server is a powerful addition to your Adobe InDesign tool set. In addition to the high quality typesetting, page-layout, color, and output features of InDesign, InDesign Server provides extra capabilities for enterprise-wide document processing.
This document gives important background information for creating scripts for InDesign Server. It provides simple examples of common scripting operations.
OTE: We strongly recommend that you develop InDesign Server scripts using InDesign CS6.
N

Intended audience

This document is for software developers who want to extend the capabilities of Adobe InDesign by writing plug-ins or by writing applications that integrate InDesign with a publication workflow. This document assumes that:
You are a programmer with a working understanding of one of the supported scripting languages:
AppleScript, JavaScript, or Visual Basic.
You have a basic understanding of the InDesign scripting object model.
You have a basic understanding of TCP/IP-based, client-server environments.
You are familiar with SOAP and know how to use it.
You are familiar with your system’s and your network server’s port configurations and know how to
configure them.
You or your team are experienced at building and supporting customer solutions.

For more information

Getting Started with Adobe InDesign Server Development provides basic information about running InDesign Server, including installation instructions and system requirements. It includes a simple demonstration of InDesign Server’s capabilities.
To learn scripting terminology and to understand the InDesign object model, read "Scripting and the InDesign object model" in the Adobe InDesign Scripting Tutorial.
Adobe InDesign Scripting Guide provides details on creating scripts for InDesign.
For details about AppleScript, VBScript, or JavaScript, see the documentation for those languages.

InDesign online scripting resources

For more information on InDesign Server scripting, see the following Web sites:
http://partners.adobe.com/public/developer/scripting/index.html
4
CHAPTER Introduction For more information 5
http://forums.adobe.com/community/indesign/indesign_scripting— The InDesign scripting
user-to-user forum. In the forum, scripters can ask questions, post answers, and share their newest scripts. The forum contains hundreds of sample scripts.
http://www.adobe.com/products/indesign/scripting/index.html
2

Getting Started

This chapter introduces the languages used for scripting and the differences between scripting for InDesign Server and for InDesign. It provides instructions for creating a simple script and for converting InDesign scripts to InDesign Server scripts. And it provides a simple script for running scripts.

What you need for InDesign Server scripting

The language you use to write scripts depends on the scripting system of your platform: AppleScript for Mac OS®, VBScript for Windows®, or JavaScript for either platform. Although the scripting languages differ, the ways in which they work with InDesign are very similar.
Each sample script in this document is shown in all three scripting languages. Translating a script from one language to another is fairly easy.

JavaScript

InDesign supports JavaScript for cross-platform scripting in both Mac OS and Windows. InDesign’s JavaScript support is based on an Adobe implementation of JavaScript known as ExtendScript. The ExtendScript interpreter conforms to the current, ECMA 262 standard for JavaScript. All language features of JavaScript 1.5 are supported. Adobe Illustrator®, Adobe Photoshop®, and other Adobe Creative Suite® products also use the ExtendScript JavaScript interpreter.
While you can write scripts using other versions of JavaScript, like Microsoft® JScript (on Windows) or Late Night Software’s OSA JavaScript (on Mac OS), the terms you use in those languages are not the same as the terms you use in ExtendScript. ExtendScript examples do not work in other JavaScript versions.
Because ExtendScript tools and features are used in several Adobe products, we consolidated all ExtendScript documentation. To learn more about JavaScript utilities like the ScriptUI user-interface module and the ExtendScript Toolkit (a JavaScript development environment and object-model inspector), see JavaScript Tools Guide.
You can also create scripts for InDesign Server that interact with other Creative Suite 5 applications, using ActionsScript and the Creative Suite extensibility model; see
page 7.

Windows

To use InDesign scripting in Windows, you can use JavaScript or some version of Microsoft Visual Basic, like VBScript.
The Visual Basic tutorial scripts in this document are written in VBScript. We chose VBScript because no added software is required to run or edit VBScripts.
Other versions of Visual Basic include Visual Basic 5 Control Creation Edition (CCE), Visual Basic 6, Visual Basic .NET, and Visual Basic 2005 Express Edition. Versions of Visual Basic before Visual Basic .NET work well with InDesign scripting. Visual Basic .NET and newer versions do not work as well, because they lack the
Variant data type, which is used extensively in InDesign scripting.
Other JavaScript development options” on
6
CHAPTER Getting Started Using Scripts from this Document 7
Many applications contain Visual Basic for Applications (VBA), such as Microsoft Word, Microsoft Excel, Microsoft Visio, or AutoCAD. Although you can use VBA to create InDesign scripts, InDesign does not include VBA.
To use VBScript or Visual Basic for InDesign scripting in Windows XP, you must install InDesign from a user account that has Administrator privileges. After you complete the installation, any user can run InDesign scripts, and any user can add scripts to the InDesign Scripts panel.

Mac OS

To use InDesign scripting on Mac OS, you can use AppleScript or JavaScript. To write AppleScripts, you must have AppleScript version 1.6 or higher and an AppleScript script editor. AppleScript comes with all Apple® systems, and it can be downloaded gratis from the Apple Web site. The Apple Script Editor is included with the Mac OS. Third-party script editors also are available; for example, Script Debugger (from Late Night Software, http://www.latenightsw.com).

Using Scripts from this Document

To use any script from this document:
1. Copy the script from this Adobe PDF document and paste it into your script editor, such as the Apple Script Editor (for AppleScript examples), ExtendScript Toolkit (for JavaScript examples), or a text editor like Notepad (for VBScript examples).
2. Save the script as a plain text file, using the appropriate file extension:
AppleScript: JavaScript: .jsx VBScript: .vbs
3. Run the script from your script editor, or send the script to InDesign Server using the sample client.
N
OTE: If you are entering the JavaScript examples, it is very important to use the same capitalization shown
in the example. JavaScript is case-sensitive, and the scripts will fail if they do not use the capitalization shown. The AppleScript and VBScript examples are not case-sensitive.
OTE: If you are copying and pasting scripts from this document, be aware that line breaks caused by the
N
layout of the document can cause errors in your script. As it can be very difficult to find such errors, we recommend that you use the scripts in the zip archive.
.applescript

Other JavaScript development options

You can use the ExtendScript Toolkit to create JavaScript scripts explicitly for InDesign Server, or you can use the Creative Suite Extension Builder (CS Extension Builder) to develop CS extensions in ActionScript. CS extensions are Flash-based (SWF) and can potentially work in a variety of Creative Suite applications.
Creative Suite applications have an extensibility infrastructure that allows developers to extend the capabilities of the applications; the infrastructure is based on Flash/Flex technology, and each CS extension is delivered as a compiled Flash (SWF) file. Creative Suite includes the Extension Manager to enable installation of CS extensions.
CHAPTER Getting Started InDesign and InDesign Server 8
An example of a Creative Suite extension that ships with the point products is Adobe Kuler. Kuler has a consistent user interface across the different suite applications, but has different logic in each, adapted to the host application.
The user interface for an extension is written in ActionScript, using the Flex framework. A CS extension is typically accessed through its own menu item in the application’s Extensions menu. CS Extension Builder allows you to design the user interface interactively using the Design view of FlashBuilder. It also allows you to develop all of the application logic for your CS6 extension in ActionScript; you can develop and debug your extension in the familiar FlashBuilder environment.
To develop your application logic, we recommend using the Creative Suite ActionScript Wrapper Library
CSAWLib), which exposes the scripting DOM of each host application as an ActionScript library. This is
( tightly integrated with the CS Extension Builder environment, which includes wizards to help you build your extension’s basic structure, and run and debug your code against suite applications such as Adobe InDesign, Photoshop and Illustrator.
The methods, properties, and behavior of the scripting DOM is as described in the JavaScript Scripting Reference for the host application. For details of how to use CS Extension Builder and the wrapper libraries, see the Creative Suite SDK documentation, which is accessible from within the Flash Builder or Eclipse Help system when you have installed CS Extension Builder.

InDesign and InDesign Server

This document presents scripts that show how to create simple documents using InDesign Server. The bulk of the scripting documentation for InDesign Server, however, is in the documentation for the desktop (that is, nonserver) version of InDesign.
We assume that you are developing your InDesign Server scripts using InDesign CS6, and that you have read Adobe InDesign Scripting Tutorial and Adobe InDesign Scripting Guide for the scripting language you want to use.
We also assume that you are familiar with the details of your InDesign Server installation. For the purposes of this document, we present sample scripts that work with a copy of InDesign Server on the same system as your scripting development environment.
InDesign is an essential tool for developing scripts for InDesign Server. We assume that you will develop scripts using InDesign before using them with InDesign Server, because it is much easier to test and debug scripts when you can see the objects being created. To see the result of your script in InDesign Server, you would have to save the document and open it using InDesign, or export the document and view the exported file in another program (like Acrobat® or Adobe Reader®). If you use InDesign to develop your InDesign Server scripts, you can reduce your development time dramatically.
Though the two programs are very similar, their scripting object models differ slightly. The following sections discuss objects, properties, and methods in InDesign that are not in InDesign Server. Keep these in mind as you convert scripts from InDesign to InDesign Server.

Active document

Many InDesign scripts refer to the front-most document in the user interface using the active document (AppleScript), activeDocument (JavaScript), or ActiveDocument (VBScript) property of the application object. This property does not exist in InDesign Server. Instead, you can refer to documents by their index or name.
CHAPTER Getting Started Your first InDesign Server script 9

Active script

Many InDesign scripts refer to the currently running script to locate other script files or resources. InDesign Server does not have this property. Instead, locate the assets the script will need in specific locations on your server or system, then refer to those locations using complete file paths.

Active windows and spreads

InDesign scripts often refer to the active window or the active spread of the active window. These user-interface properties are not supported by InDesign server.

Selection

As you would expect, InDesign server does not have an object corresponding to the user selection. When you convert scripts from InDesign, you must remove any reference to the selection and provide references to objects based on other qualities (like the object id, index, or label).

Dialogs

InDesign can create modal dialog boxes using the dialog object and populate them with common user-interface controls, like check boxes, text-entry fields, and radio buttons. InDesign server does not support the dialog object or any user-interface controls.

Copy and paste

Because InDesign Server has no user interface, it also lacks the copy and paste features of InDesign. Instead of using copy and paste, use duplicate and move. Both methods can create copies of objects, and can move objects from one document to another.

Your first InDesign Server script

The traditional first project in any programming language is to display, or print, the message “Hello World!” In this example, we create a new InDesign Server publication, add a frame containing this message, and save the document. At that point, you can open and view the document using InDesign.
OTE: These examples assume that you are entering and running the script on the system on which
N
InDesign Server is installed. For instructions on running scripts using the Test Client or SOAP commands, see Introduction to Adobe InDesign Server Development.

AppleScript

To create an AppleScript script:
1. Locate and open the AppleScript Editor.
2. Enter the following script. The lines preceded by double dashes ( the scripting system. They are included to describe the operation of the program. As you look through the script, you will see how we create, then address, each object in turn. The AppleScript command
tell specifies which object will receive the next message we send.
--) are comments and are ignored by
CHAPTER Getting Started Your first InDesign Server script 10
--HelloWorld.applescript tell application "InDesignServer"
--Create a new document. set myDocument to make document
--Get a reference to the first page. tell myDocument
--Create a new text frame on the first page. tell page 1
set myTextFrame to make text frame
--Change the size of the text frame. set geometric bounds of myTextFrame to {"6p", "6p", "18p", "18p"}
--Enter text in the text frame. set contents of myTextFrame to "Hello World!"
end tell
--Save the file (fill in a valid file path). save to "Macintosh HD:HelloWorld.indd"
end tell
--Close the document. close document 1
end tell
3. Save the script as a text file with the file extension .applescript.
4. To run the script from the Script Editor, click the Run button.
5. Open and view the document with InDesign.

JavaScript

To create a Jav a S cript:
1. Using the ExtendScript Toolkit, enter the following script:
//HelloWorld.jsx //Create a new document. var myDocument = app.documents.add(); //Get a reference to the first page. var myPage = myDocument.pages.item(0); //Create a text frame. var myTextFrame = myPage.textFrames.add(); //Specify the size and shape of the text frame. myTextFrame.geometricBounds = ["6p0", "6p0", "18p0", "18p0"]; //Enter text in the text frame. myTextFrame.contents = "Hello World!"; //Save the document (fill in a valid file path). myDocument.save(new File("/c/HelloWorld.indd")); //Close the document. app.documents.item(0).close();
2. Save the text as a plain text file with the file extension .jsx.
3. Choose InDesign Server from the target drop-down menu.
4. Click Run.
5. Open and view the document with InDesign.
CHAPTER Getting Started Adding features to “Hello World” 11

VBScript

To create a VB S cript:
1. Using any text editor (such as Notepad), enter the following script:
Rem HelloWorld.vbs Set myInDesignServer = CreateObject("InDesignServer.Application") Rem Create a new document. Set myDocument = myInDesignServer.Documents.Add Rem Get a reference to the first page. Set myPage = myDocument.Pages.Item(1) Rem Create a text frame. Set myTextFrame = myPage.TextFrames.Add Rem Specify the size and shape of the text frame. myTextFrame.GeometricBounds = Array("6p0", "6p0", "18p0", "18p0") Rem Enter text in the text frame. myTextFrame.Contents = "Hello World!" Rem Save the document (fill in a valid file path). myDocument.Save "c:\HelloWorld.indd" Rem Close the document. myInDesignServer.Documents.Item(1).Close
2. Save the file as text with the file extension .vbs.
3. Use the InDesign Server sample client to run the script.
4. Open and view the document with InDesign.

Adding features to “Hello World”

Next, we create a script that creates another “Hello World” document. Our second script will do the following:
Use a function (or handler in AppleScript) to get the page dimensions and page margins of a
document.
Resize a text frame.
Change the formatting of the text in the text frame.
Export as PDF.

AppleScript

To create the script:
1. Choose File > New in the Script Editor and enter the following script:
CHAPTER Getting Started Adding features to “Hello World” 12
--ImprovedHelloWorld.applescript tell application "InDesignServer"
set myDocument to make document set myPage to page 1 of myDocument tell myPage
set myTextFrame to make text frame end tell set contents of myTextFrame to "Hello World!"
--Get page width and page height using the function "myGetBounds". set myBounds to my myGetBounds(myDocument, myPage)
--Resize the text frame to match the publication margins. set geometric bounds of myTextFrame to myBounds set myParagraph to object reference of paragraph 1 of myTextFrame
--Change the font, size, and alignment.
--Enter the name of a font on your system, if necessary. try
set myFont to font "Arial" of application "InDesignServer"
set applied font of myParagraph to myFont end try
--Change the size of the text. set point size of myParagraph to 48
--Set the justification of the paragraph to center align. set justification of myParagraph to center align
--Set the first baseline offset of the text frame to ascent. set first baseline offset of text frame preferences of myTextFrame to ascent offset
--Set the vertical justification of the text frame to center. set vertical justification of text frame preferences of myTextFrame to center align
--Export the document as PDF (fill in a valid file path).
tell myDocument
--You'll need to fill in a valid file path on your system.
export format PDF type to "Macintosh HD:ImprovedHelloWorld.pdf" end tell
--Close the document. close document 1 saving no
end tell on myGetBounds(myDocument, myPage)
tell application "InDesignServer"
set myPageHeight to page height of document preferences of myDocument
set myPageWidth to page width of document preferences of myDocument
tell margin preferences of myPage
if side of myPage is left hand then
set myX2 to left set myX1 to right
else
set myX1 to left
set myX2 to right end if set myY1 to top set myY2 to bottom
end tell set myX2 to myPageWidth - myX2 set myY2 to myPageHeight - myY2 return {myY1, myX1, myY2, myX2}
end tell
end myGetBounds
2. Save the script as a text file with the file extension .applescript.
CHAPTER Getting Started Adding features to “Hello World” 13
3. To run the script, click the Run button in the Script Editor.
4. Open and view the exported PDF with Acrobat or Adobe Reader.

JavaScript

To create the script:
1. Using the ExtendScript Toolkit, enter the following script:
//ImprovedHelloWorld.jsx var myDocument = app.documents.add(); var myPage = myDocument.pages.item(0); var myTextFrame = myPage.textFrames.add(); myTextFrame.contents = "Hello World!"; //Get page width and page height using the function "myGetBounds". myBounds = myGetBounds(myDocument, myPage); //Resize the text frame to match the publication margins. myTextFrame.geometricBounds = myBounds; var myParagraph = myTextFrame.paragraphs.item(0); //Change the font, size, and alignment. //Enter the name of a font on your system, if necessary. try {
var myFont = app.fonts.item("Arial");
myParagraph.appliedFont = myFont; } catch (e){} //Change the size of the text. myParagraph.pointSize = 48; //Set the justification of the paragraph to center align. myParagraph.justification = Justification.centerAlign //Set the first baseline offset of the text frame to ascent. myTextFrame.textFramePreferences.firstBaselineOffset = FirstBaseline.ascentOffset; //Set the vertical justification of the text frame to center. myTextFrame.textFramePreferences.verticalJustification = VerticalJustification.centerAlign; //Export the document as PDF (fill in a valid file path). myDocument.exportFile(ExportFormat.pdfType, new File("/c/ImprovedHelloWorld.pdf")); //Close the document. app.documents.item(0).close(); function myGetBounds(myDocument, myPage){
var myPageWidth = myDocument.documentPreferences.pageWidth;
var myPageHeight = myDocument.documentPreferences.pageHeight
if(myPage.side == PageSideOptions.leftHand){
var myX2 = myPage.marginPreferences.left;
var myX1 = myPage.marginPreferences.right; } else{
var myX1 = myPage.marginPreferences.left;
var myX2 = myPage.marginPreferences.right; }
var myY1 = myPage.marginPreferences.top; var myX2 = myPageWidth - myX2; var myY2 = myPageHeight - myPage.marginPreferences.bottom; return [myY1, myX1, myY2, myX2];
}
CHAPTER Getting Started Adding features to “Hello World” 14
2. Save the text as a plain text file with the file extension .jsx.
3. Choose InDesign Server from the target drop-down menu.
4. Click the Run button.
5. Open and view the exported PDF with Acrobat or Adobe Reader.

VBScript

To create the script:
1. Start any text editor (such as Notepad) and enter the following script:
Rem ImprovedHelloWorld.vbs Set myInDesignServer = CreateObject("InDesignServer.Application") Set myDocument = myInDesignServer.Documents.Add Set myPage = myDocument.Pages.Item(1) Set myTextFrame = myPage.TextFrames.Add myTextFrame.Contents = "Hello World!" Rem Get page width and page height using the function "myGetBounds". myBounds = myGetBounds(myDocument, myPage) Rem Resize the text frame to match the publication margins. myTextFrame.GeometricBounds = myBounds Set myParagraph = myTextFrame.Paragraphs.Item(1)
Rem Change the font, size, and alignment. Rem Enter the name of a font on your system, if necessary. If TypeName(myInDesignServer.Fonts.Item("Arial"))<>"Nothing" Then
Set myFont = myInDesignServer.Fonts.Item("Arial") myParagraph.AppliedFont = myFont
End If myParagraph.PointSize = 48 Rem If you are running the script using the Application.DoScript Rem method, you can use the full name of the justification enumeration: Rem myParagraph.Justification = idJustification.idCenterAlign Rem If you are running the script from Windows Explorer, use Rem the decimal version of the enumeration: myParagraph.Justification = 1667591796 Rem Set the first baseline offset of the text frame to ascent. Rem If you are running the script using the Application.DoScript Rem method, you can use the full name of the justification enumeration: Rem myTextFrame.TextFramePreferences.FirstBaselineOffset = idFirstBaseline.idAscentOffset Rem If you are running the script from Windows Explorer, use Rem the decimal version of the enumeration: myTextFrame.TextFramePreferences.FirstBaselineOffset = 1296135023 Rem Set the vertical justification of the text frame to center. Rem If you are running the script using the Application.DoScript Rem method, you can use the full name of the justification enumeration: Rem myTextFrame.TextFramePreferences.VerticalJustification = idVerticalJustification.idCenterAlign Rem If you are running the script from Windows Explorer, use Rem the decimal version of the enumeration: myTextFrame.TextFramePreferences.VerticalJustification = 1667591796 Rem Export the document as PDF (fill in a valid file path). Rem myDocument.Export idExportFormat.idPDFType "c:\ImprovedHelloWorld.indd" myDocument.Export 1952403524, "c:\ImprovedHelloWorld.pdf" Rem Close the document.
CHAPTER Getting Started A simple script for running scripts 15
myInDesignServer.Documents.Item(1).Close Function myGetBounds(myDocument, myPage)
myPageWidth = myDocument.documentPreferences.pageWidth myPageHeight = myDocument.documentPreferences.pageHeight If myPage.Side = idPageSideOptions.idLeftHand Then
myX2 = myPage.marginPreferences.Left
myX1 = myPage.marginPreferences.Right Else
myX1 = myPage.marginPreferences.Left
myX2 = myPage.marginPreferences.Right End If myX2 = myPageWidth - myX2 myY1 = myPage.marginPreferences.Top myY2 = myPageHeight - myPage.marginPreferences.bottom myGetBounds = Array(myY1, myX1, myY2, myX2)
End Function
2. Save the text as a plain text file with the file extension .vbs.
3. Use the InDesign Server sample client to run the script.
4. Open and view the exported PDF with Acrobat or Adobe Reader.

A simple script for running scripts

Another way to run a script in InDesign Server is to take advantage of the do script (in AppleScript;
doScript in JavaScript; or DoScript in VBScript) method to send a script to the application. This gives you
a way to send JavaScripts directly to the application, rather than running them from the ExtendScript Toolkit. In this section, we provide AppleScript and VBScript examples that you can run from the Finder (on Mac OS) or Explorer (on Windows). For more information about working with the Adobe InDesign Scripting Guide.
This script is something like a miniature sample client for use on your local system.

AppleScript

set myScript file to choose file with prompt "Select a script file:" tell application "Finder"
set myFileExtension to name extension of myScriptFile end tell tell application "Adobe InDesign Server CS6"
if myFileExtension is "jsx" then
do script myScriptFile language javascript else
do script myScriptFile language applescript language end if end tell
do script method, see
CHAPTER Getting Started Converting an InDesign script to InDesign Server 16

VBScript

Set myDialog = CreateObject("UserAccounts.CommonDialog") myDialog.Filter = "JavaScript Files|*.jsx|VBScript Files|*.vbs|" myDialog.FilterIndex = 1 myDialog.InitialDir = "C:\" myResult = myDialog.ShowOpen If myResult = True Then
myScriptFile = myDialog.FileName
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
myFileExtension = myFileSystemObject.GetExtensionName(myScriptFile)
If myFileExtension = "jsx" Or myFileExtension = "vbs" Then
Set myInDesign = CreateObject("InDesign.Application") Rem Use the decimal form of the enumerations, since this script Rem will be run from Explorer. If myFileExtension = "jsx" Then
Rem idScriptLanguage.idJavaScript = 1246973031 myInDesign.DoScript myScriptFile, 1246973031
Else
Rem idScriptLanguage.idVisualBasic = 1447185511 myInDesign.DoScript myScriptFile, 1447185511
End If
End If End If

Converting an InDesign script to InDesign Server

InDesign comes with a variety of sample scripts, some of which might be useful in an InDesign Server production environment. The FindChangeByList script is a good example; it performs a series of find/change operations defined by a tab-delimited text file. The functions in this script could be very useful if your use of InDesign server involves many find/change operations.
The following steps show how to convert FindChangeByList to an InDesign Server script (see FindChangeByList for the complete script).

AppleScript

1. Replace the main handler with the following:
on main()
tell application "InDesign Server"
if (count documents) is greater than 0 then
--Provide a story object or a document object my myFindChangeByList(document 1, false)
end if
end tell
end main
2. Delete the myDisplayDialog handler.
3. Change the line:
set myFindChangeFile to my myFindFile("FindChangeSupport:FindChangeList.txt")
to (you will have to fill in a valid file path for your system):
Loading...
+ 36 hidden pages