Adobe 0046100128056 Scripting Guide

Adobe 0046100128056 - InDesign - Mac Manual

Adobe 0046100128056 manual content summary:

  • Adobe 0046100128056 | Scripting Guide - Page 1
    ADOBE® INDESIGN® CS5 ADOBE INDESIGN CS5 SCRIPTING GUIDE: JAVASCRIPT
  • Adobe 0046100128056 | Scripting Guide - Page 2
    in any form or by any means, electronic, mechanical, recording, or otherwise, without the prior written permission of Adobe Systems Incorporated. Please note that the content in this guide is protected under copyright law even if it is not distributed with software that includes an end user license
  • Adobe 0046100128056 | Scripting Guide - Page 3
    the Structure of the Scripts 9 For More Information 10 Other JavaScript development options 10 2 Scripting Features 11 Script Preferences 11 Getting margins and columns 24 Changing the appearance of the pasteboard 25 Guides and grids 26 Changing measurement units and ruler 28 Defining and
  • Adobe 0046100128056 | Scripting Guide - Page 4
    print preferences 41 Printing with printer presets 44 Exporting a Document as PDF 44 Exporting to PDF 45 Setting PDF export options 45 Exporting a range of pages to PDF 46 Exporting individual pages to PDF 47 Exporting PDF with Interactive Features 48 Exporting Pages as EPS 48 Exporting all
  • Adobe 0046100128056 | Scripting Guide - Page 5
    Contents 5 6 Text and Type 71 Entering and Importing Text 71 Creating a text frame 71 Adding text 72 Stories and text frames 72 Replacing text 73 Inserting special characters 73 Placing Text and Setting Text-Import Preferences 74 Exporting Text and Setting Text-Export Preferences 77
  • Adobe 0046100128056 | Scripting Guide - Page 6
    131 Adding Menus and Menu Items 131 Menus and Events 132 Working with scriptMenuActions 133 A More Complex Menu-scripting Example 134 10 Working with Preflight 140 Exploring Preflight Profiles 140 Listing preflight profiles 140 Listing preflight rules 141 Listing preflight data objects 141
  • Adobe 0046100128056 | Scripting Guide - Page 7
    XML element 168 Duplicating an XML element 168 Removing items from the XML structure 169 Creating an XML comment 169 Creating an XML processing instruction 169 Working with XML attributes 169 Working with XML stories 170 Exporting XML 170 Adding XML Elements to a Layout 171 Associating XML
  • Adobe 0046100128056 | Scripting Guide - Page 8
    Contents 8 Why use XML rules 179 XML-rules programming model 179 XML Rules Examples 185 Setting up a sample document 185 Getting started with XML rules 186 Changing the XML structure using XML rules 190 Duplicating XML elements with XML rules 191 XML rules and XML attributes 192 Applying
  • Adobe 0046100128056 | Scripting Guide - Page 9
    all of the scripts shown in this document is available at the InDesign scripting home page, at: http://www.adobe.com/products/indesign/scripting/index.html. After you have downloaded and expanded the archive, move the folders corresponding to the scripting language(s) of your choice into the Scripts
  • Adobe 0046100128056 | Scripting Guide - Page 10
    More Information 10 For More Information ) to develop CS extensions in ActionScript. CS extensions are Flash-based (SWF) and can potentially work in a variety debug your code against suite applications such as Adobe InDesign, Photoshop and Illustrator. The methods, properties, and behavior of the
  • Adobe 0046100128056 | Scripting Guide - Page 11
    with script labels. X Running scripts at InDesign start-up. X Controlling the ExtendScript engine in which scripts execute. We assume you already read Adobe InDesign CS5 Scripting Tutorial and know how to write, install, and run InDesign scripts in the scripting language of your choice. Script
  • Adobe 0046100128056 | Scripting Guide - Page 12
    CHAPTER 2: Scripting Features Getting the Current Script 12 Property Description userInteractionLevel This property controls the alerts and dialogs InDesign presents to the user. When you set this property to UserInteractionLevels.neverInteract, InDesign does not display any alerts or dialogs.
  • Adobe 0046100128056 | Scripting Guide - Page 13
    CHAPTER 2: Scripting Features Using the doScript Method 13 X Compilation - This involves mapping the names in the script to the underlying script ids, which are what the application understands. The mechanics of compilation are language specific. X Interpretation - This involves matching the ids
  • Adobe 0046100128056 | Scripting Guide - Page 14
    (1), vbOKOnly, \"First argument: \" & arguments(0)"; app.doScript(myVBScript, ScriptLanguage.visualBasic, myParameters); } else{ var myAppleScript = "tell application \"Adobe InDesign CS5\\rdisplay dialog(\"First argument\" & item 1 of arguments & return & \"Second argument: \" & item 2 of arguments
  • Adobe 0046100128056 | Scripting Guide - Page 15
    CHAPTER 2: Scripting Features Using the doScript Method 15 //To send parameters to a script run using app.doScript(), the doScript //statement must not appear inside a function. If it does, the parameters //will not be passed to the script. var myDocument = app.documents.add(); var myPage =
  • Adobe 0046100128056 | Scripting Guide - Page 16
    Create a string to be run as a AppleScript. p1 = "tell application \"Adobe InDesign CS5\"\r"; p2 = "tell script args" +"\r"; p3 = "set value using the tools presented by the user interface, this does not present any problem. For scripts, which can perform thousands of actions in the time a human being
  • Adobe 0046100128056 | Scripting Guide - Page 17
    .pageHeight; // //Create 10 random page items. for(var i = 0; i < 10; i++) { myX1 = myGetRandom .random()*myRange); } return myRandom; } In addition, all objects that support the label property also support custom labels. A script can set a custom label using the insertLabel
  • Adobe 0046100128056 | Scripting Guide - Page 18
    when InDesign starts, put the script in the Startup Scripts folder in the Scripts folder (for more information, see "Installing Scripts" in Adobe InDesign CS5 Scripting Tutorial). NOTE: Scripts run in the session ExtendScript engine when InDesign starts can create objects and functions that will be
  • Adobe 0046100128056 | Scripting Guide - Page 19
    columns and margins. X Change the appearance of the pasteboard. X Use guides and grids. X Change measurement units and ruler origin. X Define and X Export a document as Adobe PDF. X Export pages of a document as EPS. We assume that you have already read Adobe InDesign CS5 Scripting Tutorial and
  • Adobe 0046100128056 | Scripting Guide - Page 20
    CHAPTER 3: Documents Basic Document Operations 20 Basic Document Operations Opening, closing, and saving documents are some of the most basic document tasks. This section shows how to do them using scripting. Creating a new document The following script shows how to make a new document using
  • Adobe 0046100128056 | Scripting Guide - Page 21
    CHAPTER 3: Documents Basic Document Operations 21 Saving a document In the InDesign user interface, you save a file by choosing File > Save, and you save a file to another file name by choosing File > Save As. In InDesign scripting, the save method can do either operation, as shown in the
  • Adobe 0046100128056 | Scripting Guide - Page 22
    CHAPTER 3: Documents Basic Page Layout 22 //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 (
  • Adobe 0046100128056 | Scripting Guide - Page 23
    outside the page margins that can be printed or included in an exported PDF. Typically, these areas are used for objects that extend beyond the page widths and heights, you can control the color used to draw the guides defining the bleed and slug. This property is not in the documentPreferences
  • Adobe 0046100128056 | Scripting Guide - Page 24
    CHAPTER 3: Documents Basic Page Layout 24 with(app.activeDocument.pasteboardPreferences){ //Any of InDesign's guides can use the UIColors constants... bleedGuideColor = UIColors.cuteTeal; slugGuideColor = UIColors.charcoal; //...or you can specify an array of RGB values (with values from 0 to 255)
  • Adobe 0046100128056 | Scripting Guide - Page 25
    CHAPTER 3: Documents Basic Page Layout 25 There are two solutions. The first is to set the margins of the existing pages before you try to change the page size, as shown in the following script fragment (from the PageMarginsForSmallPages tutorial script): var myDocument = app.documents.add();
  • Adobe 0046100128056 | Scripting Guide - Page 26
    easy to position objects on your document pages. These are very useful items to add when you are creating templates for others to use. Defining guides Guides in InDesign give you an easy way to position objects on the pages of your document. The following script fragment shows how to use
  • Adobe 0046100128056 | Scripting Guide - Page 27
    color, fit margins, remove existing, layer. //Note that the createGuides method does not take an RGB array //for the guide color parameter. createGuides(4, 4, "1p", "1p", UIColors.gray, true, true, myDocument.layers.item(0)); } Setting grid preferences To control the properties of the document and
  • Adobe 0046100128056 | Scripting Guide - Page 28
    are in the properties of the guidePreferences and gridPreferences objects. The following script fragment shows how to set guide and grid snap properties. (For the complete script, see GuideGridPreferences.) var myDocument = app.activeDocument; with(myDocument.guidePreferences){ guidesInBack = true
  • Adobe 0046100128056 | Scripting Guide - Page 29
    CHAPTER 3: Documents Basic Page Layout 29 var myDocument = app.activeDocument with (myDocument.viewPreferences){ var myOldXUnits = horizontalMeasurementUnits; var myOldYUnits = verticalMeasurementUnits; horizontalMeasurementUnits = MeasurementUnits.points; verticalMeasurementUnits =
  • Adobe 0046100128056 | Scripting Guide - Page 30
    CHAPTER 3: Documents Basic Page Layout 30 //active window is a layout window). var myMarginPreferences = app.activeDocument.marginPreferences; left = myMarginPreferences.left; right = myMarginPreferences.right; top = myMarginPreferences.top; bottom = myMarginPreferences.bottom; columnCount =
  • Adobe 0046100128056 | Scripting Guide - Page 31
    CHAPTER 3: Documents Basic Page Layout 31 top = "4p"; bottom = "9p"; columnCount = 1; documentBleedBottom = "3p"; documentBleedTop = "3p"; documentBleedLeft = "3p"; documentBleedRight = "3p"; facingPages = true; pageOrientation = PageOrientation.portrait; pagesPerDocument = 1; slugBottomOffset = "
  • Adobe 0046100128056 | Scripting Guide - Page 32
    ), an open standard for embedding metadata in a document. To learn more about XMP, see the XMP specification at http://partners.adobe.com/asn/developer/pdf/MetadataFramework.pdf. You also can add XMP information to a document using InDesign scripting. All XMP properties for a document are in the
  • Adobe 0046100128056 | Scripting Guide - Page 33
    Documents Basic Page Layout 33 var myDocument = app.documents.add(); with (myDocument.metadataPreferences){ author = "Adobe"; copyrightInfoURL = "http://www.adobe.com"; copyrightNotice = "This document is copyrighted."; copyrightStatus = CopyrightStatus.yes; description = "Example of xmp metadata
  • Adobe 0046100128056 | Scripting Guide - Page 34
    .colors.add({name:"PageNumberRed", model:ColorModel.process, colorValue:[20, 100, 80, 10]}); } //Next, set up some default styles. //Create up a character style rightAlign, pointSize:11, leading:14}); } //Create a layer for guides. try{ myDocument.layers.item("GuideLayer").name; } catch (myError){
  • Adobe 0046100128056 | Scripting Guide - Page 35
    "]; var myNewContainer = createContainerItem("http://ns.adobe.com/xap/1.0/", "email"); setProperty("http://ns.adobe.com/xap/1.0/", "email/*[1]", "[email protected]"); } //Set up the master myDocument.documentPreferences.pageWidth marginPreferences.left; guides.add(myDocument.layers.item("GuideLayer"),
  • Adobe 0046100128056 | Scripting Guide - Page 36
    + "\rCreation Date:\t" + new Date + "\tEmail Contact\t" + getProperty("http://ns.adobe.com/xap/1.0/", "email/*[1]"); } var myLeftSlug = textFrames.add(myDocument.layers.item("Slug"), = myDocument.documentPreferences.pageWidth marginPreferences.right; guides.add(myDocument.layers.item("GuideLayer"), {
  • Adobe 0046100128056 | Scripting Guide - Page 37
    CHAPTER 3: Documents Basic Page Layout 37 undefined, {geometricBounds:[myDocument.documentPreferences.pageHeight+36, marginPreferences.left, myDocument.documentPreferences.pageHeight + 144, myRightMargin], contents:myString}); myRightSlug.parentStory.tables.add(); //Body text master text frame.
  • Adobe 0046100128056 | Scripting Guide - Page 38
    CHAPTER 3: Documents Adjusting Page Sizes and Layout 38 The same preferences can be applied to a document object by referring to a document, rather than to the application. (For the complete script for setting document preferences, see DocumentWatermark.) var myDocument = app.documents.item(0);
  • Adobe 0046100128056 | Scripting Guide - Page 39
    CHAPTER 3: Documents Adjusting Page Sizes and Layout 39 Resizing and reframing pages You can resize or reframe page items on a page by scripting. With InDesign CS5, you can also apply the resize and reframe operations to pages to change their sizes. NOTE: Your minimum page size is determined by
  • Adobe 0046100128056 | Scripting Guide - Page 40
    CHAPTER 3: Documents Adjusting Page Sizes and Layout 40 //Given a document with four pages (0, 1, 2, 3)... var myDocument = app.activeDocument; var myPages = myDocument.pages; //Rotate a page around its center point. var myRotateMatrix = app.transformationMatrices.add({
  • Adobe 0046100128056 | Scripting Guide - Page 41
    generate an error. //copies = 1; //If the printer property is set to Printer.postscript file, or if the //selected printer does not support collation, then the collating //property is unavailable. Attempting to set it will generate an error. //collating = false; reverseOrder = false; //pageRange can
  • Adobe 0046100128056 | Scripting Guide - Page 42
    CHAPTER 3: Documents Printing a Document 42 sequence = Sequences.all Properties corresponding to the controls in the //Output panel of the Print dialog box negative = true; //If a device independent PPD is specified, trying to set the colorOutput //parameter will result in an error. try{
  • Adobe 0046100128056 | Scripting Guide - Page 43
    CHAPTER 3: Documents Printing a Document 43 pagePosition = PagePositions.centered; paperGap = 0; paperOffset = 0; paperTransverse = false; scaleHeight = 100; scaleWidth = 100; scaleMode = ScaleModes.scaleWidthHeight; scaleProportional = true; } catch(myError){} //If trapping is on, attempting to
  • Adobe 0046100128056 | Scripting Guide - Page 44
    CHAPTER 3: Documents Exporting a Document as PDF 44 Properties corresponding to the controls in the //Graphics panel of the a document using a printer preset, include the printer preset in the print command. Exporting a Document as PDF InDesign scripting offers full control over the creation of
  • Adobe 0046100128056 | Scripting Guide - Page 45
    app.pdfExportPresets.item("prepress"); app.activeDocument.exportFile(ExportFormat.pdfType, File("/c/myTestDocument.pdf"), false, myPDFExportPreset); Setting PDF export options The following script sets the PDF export options before exporting. (For the complete script, see ExportPDFWithOptions.) with
  • Adobe 0046100128056 | Scripting Guide - Page 46
    = PDFMarkWeight.p125pt; registrationMarks = true; try{ simulateOverprint = false; } catch(e){} useDocumentBleedWithPDF = true; //Set viewPDF to true to open the PDF in Acrobat or Adobe Reader. viewPDF = false; } //Now export the document. You'll have to fill in your own file path. app.activeDocument
  • Adobe 0046100128056 | Scripting Guide - Page 47
    range string //(just as you would enter it in the Print or Export PDF dialog box). pageRange = "1, 3-6, 7, 9-11, 12"; } var //The name of the exported files will be the base name + the //page name + ".pdf". //If the page name contains a colon (as it will if the //document contains sections
  • Adobe 0046100128056 | Scripting Guide - Page 48
    Features The following script shows how to export a document with interactive features as a PDF. (For the complete script, see ExportInteractivePDF.) //Given a document "myDocument," add page transitions... for(var myCounter = 0; myCounter < myDocument.spreads.length; myCounter++){ myDocument
  • Adobe 0046100128056 | Scripting Guide - Page 49
    CHAPTER 3: Documents Exporting Pages as EPS 49 Exporting as EPS with file naming The following script exports each page as an EPS, but it offers more control over file naming than the earlier example. (For the complete script, see ExportEachPageAsEPS.) //Display a "choose folder" dialog box. if(
  • Adobe 0046100128056 | Scripting Guide - Page 50
    4 Working with Layers InDesign's layers are the key to controlling the stacking order of objects in your layout. You can think of layers as transparent planes stacked on top of each other. You also can use layers as an organizational tool, putting one type of content on a given layer or set of
  • Adobe 0046100128056 | Scripting Guide - Page 51
    CHAPTER 4: Working with Layers Scripting Layers 51 Scripting Layers In InDesign's user interface, you add, delete, rearrange, duplicate, and merge layers using the Layers panel. You also can change the layer to which a selected page item is assigned by dragging and dropping the layer proxy in the
  • Adobe 0046100128056 | Scripting Guide - Page 52
    CHAPTER 4: Working with Layers Scripting Layers 52 Getting the active layer The active layer is the layer on which new objects are created. You can get the active layer using scripting, as shown in the following script fragment. (For the complete script, see ActiveLayer.) //Given a document "
  • Adobe 0046100128056 | Scripting Guide - Page 53
    CHAPTER 4: Working with Layers Scripting Layers 53 Referring to ranges of layers To refer to a series of layers, you can use the itemByRange method. The following script fragment shows how to get a reference to a range of layers, then set a property on all layers in the range. (For the complete
  • Adobe 0046100128056 | Scripting Guide - Page 54
    = 72; myCounter < 172; myCounter+=10){ myPage.ovals.add({geometricBounds:[216, myCounter, 226, myCounter+10]}); } //Move all of the ovals CHARCOAL; myLayer.ignoreWrap = false; myLayer.visible = true; Working with layer guides Guides can be assigned to a specific layer, just like page items. You
  • Adobe 0046100128056 | Scripting Guide - Page 55
    export the "Background" //layer and each "Language" layer to PDF as separate PDF files... var myVersion, myLanguageCounter, myFileName; var myFolder = Folder.desktop } } myFileName = myFolder + "/" + myVersion + ".pdf"; myDocument.exportFile(ExportFormat.pdfType, File(myFileName)); } Locking layers
  • Adobe 0046100128056 | Scripting Guide - Page 56
    5 Working with Page Items This chapter covers scripting techniques related to the page items (rectangles, ellipses, graphic lines, polygons, text frames, buttons, and groups) that can appear in an InDesign layout. This document discusses the following: X Creating page items. X Page item geometry. X
  • Adobe 0046100128056 | Scripting Guide - Page 57
    CHAPTER 5: Working with Page Items Creating Page Items 57 change the type to a graphic line. The only things that define the type of a rectangle, ellipse, graphic line, or polygon are: X The number of paths in the object. Any page item with more than one path is a polygon. X The number and
  • Adobe 0046100128056 | Scripting Guide - Page 58
    CHAPTER 5: Working with Page Items Creating Page Items 58 X Changing the zero point location by either dragging the zero point or by changing the ruler origin changes the coordinates on the rulers. X Page items are made up of one or more paths, which, in turn, are made up of two or more path
  • Adobe 0046100128056 | Scripting Guide - Page 59
    CHAPTER 5: Working with Page Items Grouping Page Items 59 //Given a polygon "myPolygon", remove the //last path point in the first path. myPolygon.paths.item(0).pathPoints.item(-1).remove(); Grouping Page Items In the InDesign user interface, you create groups of page items by selecting them and
  • Adobe 0046100128056 | Scripting Guide - Page 60
    CHAPTER 5: Working with Page Items Duplicating and Moving Page Items 60 Note that the move method truly moves the object-when you move a page item to another document, it is deleted from the original document. To move the object to another while retaining the original, use the duplicate method (
  • Adobe 0046100128056 | Scripting Guide - Page 61
    in the Object > Convert Shape menu or the Pathfinder panel (Window > Object and Layout > Pathfinder). In InDesign scripting, page items support the convertShape method, as demonstrated in the following script fragment (for the complete script, refer to ConvertShape). //Given a rectangle "myRectangle
  • Adobe 0046100128056 | Scripting Guide - Page 62
    CHAPTER 5: Working with Page Items Transforming Page Items 62 //Given a rectangle "myRectangle"... myRectangle.convertShape(ConvertShapeOptions.convertToOpenPath); Arranging page items Page items in an InDesign layout can be arranged in front of or behind each other by adjusting their stacking
  • Adobe 0046100128056 | Scripting Guide - Page 63
    CHAPTER 5: Working with Page Items Transforming Page Items 63 The following scripting example demonstrates the basic process of transforming a page item. (For the complete script, see TransformExamples.) //Rotate a rectangle "myRectangle" around its center point. var myRotateMatrix = app.
  • Adobe 0046100128056 | Scripting Guide - Page 64
    CHAPTER 5: Working with Page Items Transforming Page Items 64 //The following statements are equivalent. slope = rise/run--so //the slope of 45 degrees is 1. myTransformationMatrix = myTransformationMatrix.shearMatrix(45); myTransformationMatrix = myTransformationMatrix.shearMatrix(undefined, 1);
  • Adobe 0046100128056 | Scripting Guide - Page 65
    CHAPTER 5: Working with Page Items Transforming Page Items 65 //Note that transformValuesOf() always returns an array //containing a single transformationMatrix. var myTransformArray = myRectangle.transformValuesOf(CoordinateSpaces.parentCoordinates); var myTransformationMatrix = myTransformArray
  • Adobe 0046100128056 | Scripting Guide - Page 66
    CHAPTER 5: Working with Page Items Transforming Page Items 66 var myRectangle = app.documents.item(0).pages.item(0).groups.item(-1).rectangles.item(0); alert("The page contains a group which has been\rrotated 45 degrees (counterclockwise).\rThe rectangle inside the group was\rrotated 45 degrees
  • Adobe 0046100128056 | Scripting Guide - Page 67
    CHAPTER 5: Working with Page Items Transforming Page Items 67 Z (x, y), bounds type, coordinate space - A point specified relative to the geometric bounds of the object (BoundingBoxLimits.geometricPathBounds) or the visible bounds of the object (BoundingBoxLimits.outerStrokeBounds) in a given
  • Adobe 0046100128056 | Scripting Guide - Page 68
    CHAPTER 5: Working with Page Items Transforming Page Items 68 Transforming points You can transform points as well as objects, which means scripts can perform a variety of mathematical operations without having to include the calculations in the script itself. The ChangeCoordinates sample script
  • Adobe 0046100128056 | Scripting Guide - Page 69
    CHAPTER 5: Working with Page Items Resize and Reframe 69 Transforming again Just as you can apply a transformation or sequence of transformations again in the user interface, you can do so using scripting. There are four methods for applying transformations again: X transformAgain X
  • Adobe 0046100128056 | Scripting Guide - Page 70
    CHAPTER 5: Working with Page Items Resize and Reframe 70 The following script fragment shows how to use the reframe method. For the complete script, see Reframe. //Given a reference to a rectangle "myRectangle"... var myBounds = myRectangle.geometricBounds; var myX1 = myBounds[1]-72; var myY1 =
  • Adobe 0046100128056 | Scripting Guide - Page 71
    are presented in order of complexity, starting with very simple scripts and building toward more complex operations. We assume that you have already read Adobe InDesign CS5 Scripting Tutorial and know how to create, install, and run a script. We also assume that you have some knowledge of working
  • Adobe 0046100128056 | Scripting Guide - Page 72
    CHAPTER 6: Text and Type Entering and Importing Text 72 function myGetBounds(myDocument, myPage){ var myPageWidth = myDocument.documentPreferences.pageWidth; var myPageHeight = myDocument.documentPreferences.pageHeight if(myPage.side == PageSideOptions.leftHand){ var myX2 = myPage.
  • Adobe 0046100128056 | Scripting Guide - Page 73
    and we supplied two characters-the starting and ending characters of the paragraph-as parameters. Inserting special characters Because the ExtendScript Toolkit supports Unicode, you can simply enter Unicode characters in text strings that you send to InDesign. Alternately, you can use the JavaScript
  • Adobe 0046100128056 | Scripting Guide - Page 74
    CHAPTER 6: Text and Type Placing Text and Setting Text-Import Preferences 74 function from this listing; you can find it in "Creating a text frame" on page 71" or in the SpecialCharacters tutorial script.) var myDocument = app.documents.item(0); //Create a text frame on the current page. var
  • Adobe 0046100128056 | Scripting Guide - Page 75
    CHAPTER 6: Text and Type Placing Text and Setting Text-Import Preferences 75 The following script shows how to place a text file in an existing text frame. (We omitted the myGetBounds function from this listing; you can find it in "Creating a text frame" on page 71," or see the
  • Adobe 0046100128056 | Scripting Guide - Page 76
    CHAPTER 6: Text and Type Placing Text and Setting Text-Import Preferences 76 The following script shows how to set Word and RTF import preferences (for the complete script, see WordRTFImportPreferences): with(app.wordRTFImportPreferences){ //convertPageBreaks property can be: //ConvertPageBreaks.
  • Adobe 0046100128056 | Scripting Guide - Page 77
    CHAPTER 6: Text and Type Exporting Text and Setting Text-Export Preferences 77 Exporting Text and Setting Text-Export Preferences The following script shows how to export text from an InDesign document. Note that you must use text or story objects to export into text file formats; you cannot
  • Adobe 0046100128056 | Scripting Guide - Page 78
    CHAPTER 6: Text and Type Exporting Text and Setting Text-Export Preferences 78 with(app.taggedTextExportPreferences){ //Options for characterSet: //TagTextExportCharacterSet.ansi //TagTextExportCharacterSet.ascii //TagTextExportCharacterSet.gb18030 //TagTextExportCharacterSet.ksc5601 //
  • Adobe 0046100128056 | Scripting Guide - Page 79
    CHAPTER 6: Text and Type Exporting Text and Setting Text-Export Preferences 79 //If the imported text did not end with a return, enter a return //to keep the stories from running together. if(myCounter != myDocument.stories.length -1){ if(myNewStory.characters.item(-1).contents != "\r"){
  • Adobe 0046100128056 | Scripting Guide - Page 80
    CHAPTER 6: Text and Type Exporting Text and Setting Text-Export Preferences 80 myEndTag = ""; //If the paragraph is not the last paragraph in the story, //omit the return character. if(myParagraph.characters.item(-1).contents == "\r"){ myString = myParagraph.texts.itemByRange(
  • Adobe 0046100128056 | Scripting Guide - Page 81
    CHAPTER 6: Text and Type Understanding Text Objects 81 ""; } myTextFile.writeln(myString); } myTextFile.writeln(""); } myTextFile.writeln("
  • Adobe 0046100128056 | Scripting Guide - Page 82
    CHAPTER 6: Text and Type Understanding Text Objects 82 document story spread, page, layer insertion points text containers characters text frame words insertion points lines characters paragraphs words text columns lines text style ranges paragraphs texts text columns notes text
  • Adobe 0046100128056 | Scripting Guide - Page 83
    CHAPTER 6: Text and Type Understanding Text Objects 83 For a text frame, the parent of the text frame usually is the page or spread containing the text frame. If the text frame is inside a group or was pasted inside another page item, the parent of the text frame is the containing page item. If
  • Adobe 0046100128056 | Scripting Guide - Page 84
    CHAPTER 6: Text and Type Understanding Text Objects 84 var myDocument = app.documents.item(0); var myPage = myDocument.pages.item(0); var myTextFrameA = myPage.textFrames.item(3); var myTextFrameB = myPage.textFrames.item(2); var myTextFrameC = myPage.textFrames.item(1); var myTextFrameD = myPage.
  • Adobe 0046100128056 | Scripting Guide - Page 85
    , deletes, or adds text while iterating through a series of text objects, you can easily end up with invalid text references. The following script demonstrates this problem. (We omitted the myGetBounds function from this listing; you can find it in "Creating a text frame" on page 71," or see the
  • Adobe 0046100128056 | Scripting Guide - Page 86
    that had been the fourth paragraph in the story; the original third paragraph is now the second paragraph and is skipped. To avoid this problem, iterate backward through the text objects, as shown in the following script. (We omitted the myGetBounds function from this listing; you can find it
  • Adobe 0046100128056 | Scripting Guide - Page 87
    CHAPTER 6: Text and Type Working with Text Frames 87 var myDocument = app.documents.item(0); var myPage = myDocument.pages.item(0); var myTextFrameA = myPage.textFrames.item(1); var myTextFrameB = myPage.textFrames.item(0); //Add a page. var myNewPage = myDocument.pages.add(); //Create another
  • Adobe 0046100128056 | Scripting Guide - Page 88
    CHAPTER 6: Text and Type Working with Text Frames 88 myObjectList.push(app.selection[myCounter]. parentTextFrames[0]); break; } } break; } } //If the object list is not empty, pass it on to the function //that does the real work. if(myObjectList.length != 0){ myBreakFrames(myObjectList); } } }
  • Adobe 0046100128056 | Scripting Guide - Page 89
    CHAPTER 6: Text and Type Working with Text Frames 89 Splitting all frames in a story The following script fragment shows how to split all frames in a story into separate, independent stories, each containing one unlinked text frame (for the complete script, see SplitStory): if(app.documents.length
  • Adobe 0046100128056 | Scripting Guide - Page 90
    CHAPTER 6: Text and Type Formatting Text 90 var myInsertionPoint = myTextFrame.paragraphs.item(0).insertionPoints.item(0); var myInlineFrame = myInsertionPoint.textFrames.add(); //Recompose the text to make sure that getting the //geometric bounds of the inline graphic will work. myTextFrame.texts
  • Adobe 0046100128056 | Scripting Guide - Page 91
    } catch(e){} autoLeading = 100; balanceRaggedLines = false; baselineShift = 0; capitalization = Capitalization.normal; composer = "Adobe Paragraph Composer"; desiredGlyphScaling = 100; desiredLetterSpacing = 0; desiredWordSpacing = 100; dropCapCharacters = 0; if(dropCapCharacters != 0){ dropCapLines
  • Adobe 0046100128056 | Scripting Guide - Page 92
    CHAPTER 6: Text and Type leftIndent = 0; ligatures = true; maximumGlyphScaling = 100; maximumLetterSpacing = 0; maximumWordSpacing = 160; minimumGlyphScaling = 100; minimumLetterSpacing = 0; minimumWordSpacing = 80; noBreak = false; otfContextualAlternate = true; otfDiscretionaryLigature = false;
  • Adobe 0046100128056 | Scripting Guide - Page 93
    >fontStyle, where familyName is the name of the font family, is a tab character, and fontStyle is the name of the font style. For example: "Adobe Caslon ProSemibold Italic"
  • Adobe 0046100128056 | Scripting Guide - Page 94
    by specifying the font family name and font style, as shown in the following script fragment: myText.appliedFont = app.fonts.item("Adobe Caslon Pro"); myText.fontStyle = "Semibold Italic"; Changing text properties Text objects in InDesign have literally dozens of properties corresponding to their
  • Adobe 0046100128056 | Scripting Guide - Page 95
    CHAPTER 6: Text and Type Formatting Text 95 myTextObject.gradientStrokeStart = [0,0]; myTextObject.gridAlignFirstLineOnly = false; myTextObject.horizontalScale = 100; myTextObject.hyphenWeight = 5; myTextObject.hyphenateAcrossColumns = true; myTextObject.hyphenateAfterFirst = 2; myTextObject.
  • Adobe 0046100128056 | Scripting Guide - Page 96
    CHAPTER 6: Text and Type Formatting Text 96 myTextObject.ruleAbove = false; myTextObject.ruleAboveColor = "Text Color"; myTextObject.ruleAboveGapColor = myDocument.swatches.item("None"); myTextObject.ruleAboveGapOverprint = false; myTextObject.ruleAboveGapTint = -1; myTextObject.
  • Adobe 0046100128056 | Scripting Guide - Page 97
    CHAPTER 6: Text and Type Formatting Text 97 Changing text color You can apply colors to the fill and stroke of text characters, as shown in the following script fragment (from the TextColors tutorial script): var myColorA, myColorB, myName; //Access the active document and page. var myDocument =
  • Adobe 0046100128056 | Scripting Guide - Page 98
    CHAPTER 6: Text and Type Formatting Text 98 the keys to text formatting productivity and should be a central part of any script that applies text formatting. The following example script fragment shows how to create and apply paragraph and character styles (for the complete script, see
  • Adobe 0046100128056 | Scripting Guide - Page 99
    CHAPTER 6: Text and Type Formatting Text 99 Why use the applyParagraphStyle method instead of setting the appliedParagraphStyle property of the text object? The applyParagraphStyle method gives the ability to override existing formatting; setting the property to a style retains local formatting.
  • Adobe 0046100128056 | Scripting Guide - Page 100
    the most powerful InDesign tools for working with text. It is fully supported by scripting, and scripts can use find/change to go far beyond what a way that adds or removes text from a story, you might face the problem of invalid text references, as discussed earlier in this chapter. In this case,
  • Adobe 0046100128056 | Scripting Guide - Page 101
    CHAPTER 6: Text and Type Finding and Changing Text 101 Finding and changing text The following script fragment shows how to find a specified string of text. While the following script fragment searches the entire document, you also can search stories, text frames, paragraphs, text columns, or any
  • Adobe 0046100128056 | Scripting Guide - Page 102
    10; myDocument.changeText(); //Clear the find/change preferences after the search. app.findTextPreferences = NothingEnum.nothing; app.changeTextPreferences = NothingEnum.nothing; Using grep InDesign supports of tagging plain text with formatting instructions) into InDesign formatted text. PageMaker
  • Adobe 0046100128056 | Scripting Guide - Page 103
    CHAPTER 6: Text and Type Finding and Changing Text 103 This is a heading. This is body text. We can create a script that uses grep find in conjunction with text find/change operations to apply formatting to the text and remove the mark-up tags, as shown in the following script
  • Adobe 0046100128056 | Scripting Guide - Page 104
    CHAPTER 6: Text and Type Working with Tables 104 } function myRemoveDuplicates(myArray){ //Semi-clever method of removing duplicate array items; much faster //than comparing every item to every other item! var myNewArray = new Array; myArray = myArray.sort(); myNewArray.push(myArray[0]); if(
  • Adobe 0046100128056 | Scripting Guide - Page 105
    CHAPTER 6: Text and Type Working with Tables 105 var myDocument = app.documents.item(0); var myStory = myDocument.stories.item(0); var myStartCharacter = myStory.paragraphs.item(6).characters.item(0); var myEndCharacter = myStory.paragraphs.item(6).characters.item(-2); var myText = myStory.texts.
  • Adobe 0046100128056 | Scripting Guide - Page 106
    CHAPTER 6: Text and Type Working with Tables 106 var myStory = myDocument.stories.item(0); var myTable = myStory.insertionPoints.item(-1).tables.add(); myTable.columnCount = 1; myTable.bodyRowCount = 1; var myArray = myGetBounds(myDocument, myDocument.pages.item(0)) var myWidth = myArray[3]-
  • Adobe 0046100128056 | Scripting Guide - Page 107
    ": if(app.selection[0].parent.parent.constructor.name == "Cell"){ alert("The selection is inside a table cell."); } break; case "Image": case "PDF": case "EPS": if(app.selection[0].parent.parent.parent.constructor.name == "Cell"){ alert("The selection is inside a table cell."); } break; default
  • Adobe 0046100128056 | Scripting Guide - Page 108
    CHAPTER 6: Text and Type Path Text 108 Path Text You can add path text to any rectangle, oval, polygon, graphic line, or text frame. The following script fragment shows how to add path text to a page item (for the complete script, see PathText): //Given a document "myDocument" with a rectangle on
  • Adobe 0046100128056 | Scripting Guide - Page 109
    = true; highlightSubstitutedGlyphs = true; justifyTextWraps = true; //kerning key increment value is 1/1000 of an em. kerningKeyIncrement = 10; //leading key increment value can range from .001 to 200 points. leadingKeyIncrement= 1; linkTextFilesWhenImporting = false; scalingAdjustsText = false
  • Adobe 0046100128056 | Scripting Guide - Page 110
    CHAPTER 6: Text and Type subscriptSize = 60; superscriptPosition = 30; superscriptSize = 60; typographersQuotes = false; useOpticalSize = false; useParagraphLeading = false; zOrderTextWrap = false; } //Text editing preferences are application-wide. with(app.textEditingPreferences){
  • Adobe 0046100128056 | Scripting Guide - Page 111
    ScriptUI component. This chapter includes some ScriptUI scripting tutorials; for more information, see Adobe CS5 JavaScript Tools Guide. We assume you already read Adobe InDesign CS5 Scripting Tutorial and know how to create and run a script. Dialog Overview An InDesign dialog box is an object like
  • Adobe 0046100128056 | Scripting Guide - Page 112
    CHAPTER 7: User Interfaces Your First InDesign Dialog 112 Dialog box element Text-edit fields Numeric-entry fields Pop-up menus Control that combines a text-edit field with a pop-up menu Check box Radio buttons InDesign name Text editbox control Real editbox, integer editbox, measurement editbox,
  • Adobe 0046100128056 | Scripting Guide - Page 113
    World" 113 Adding a User Interface to "Hello World" In this example, we add a simple user interface to the Hello World tutorial script presented in Adobe InDesign CS5 Scripting Tutorial. The options in the dialog box provide a way for you to specify the sample text and change the point size of
  • Adobe 0046100128056 | Scripting Guide - Page 114
    CHAPTER 7: User Interfaces Creating a More Complex User Interface 114 For the complete script, see ComplexUI. var myDialog = app.dialogs.add({name:"User Interface Example Script", canCancel:true}); with(myDialog){ //Add a dialog column. with(dialogColumns.add()){ //Create a border panel. with(
  • Adobe 0046100128056 | Scripting Guide - Page 115
    CHAPTER 7: User Interfaces Creating a More Complex User Interface 115 ({staticLabel:"Left", checkedState:true}); var myCenterRadioButton = radiobuttonControls.add ({staticLabel:"Center"}); var myRightRadioButton = radiobuttonControls.add({staticLabel:"Right Display the dialog box. if(myDialog.
  • Adobe 0046100128056 | Scripting Guide - Page 116
    .verticalJustification = myVerticalJustification; } } } } Working with ScriptUI JavaScripts can make create and define user-interface elements using an Adobe scripting component named ScriptUI. ScriptUI gives scripters a way to create floating palettes, progress bars, and interactive dialog boxes
  • Adobe 0046100128056 | Scripting Guide - Page 117
    CHAPTER 7: User Interfaces Working with ScriptUI 117 The following script fragment shows how to call the progress bar created in the above script using a separate JavaScript (for the complete script, see CallProgressBar): Rem Create a document and add pages to it-Rem if you do not do this, the
  • Adobe 0046100128056 | Scripting Guide - Page 118
    are presented in order of complexity, starting with very simple scripts and building toward more complex operations. We assume that you have already read Adobe InDesign CS5 Scripting Tutorial and know how to create, install, and run a script. For a discussion of events related to menus, see Chapter
  • Adobe 0046100128056 | Scripting Guide - Page 119
    CHAPTER 8: Events Working with Event Listeners 119 triggering any qualifying eventListeners registered to objects above the target in the scripting object model hierarchy. The following table provides more detail on the properties of an event and the ways in which they relate to event propagation
  • Adobe 0046100128056 | Scripting Guide - Page 120
    folder. (For more on installing scripts, see "Installing Scripts" in Adobe InDesign CS5 Scripting Tutorial.) When you add an eventListener script to a saved with the document or exported to IDML. NOTE: If you are having trouble with a script that defines an eventListener, you can either run a script
  • Adobe 0046100128056 | Scripting Guide - Page 121
    CHAPTER 8: Events Sample afterNew Event Listener 121 myString += "\rCurrent: " +myEvent.currentTarget + " " + myEvent.currentTarget.name; myString += "\r\rPhase: " + myGetPhaseName(myEvent.eventPhase ); myString += "\rBubbles: " + myEvent.bubbles; myString += "\r\rCancelable: " +myEvent.cancelable
  • Adobe 0046100128056 | Scripting Guide - Page 122
    , contents:"Created: " + myEvent.timeStamp + "\rby: " + app.userName}); } } } function myAddXMPData(myDocument){ with(myDocument.metadataPreferences){ author = "Adobe Systems"; description = "This is a sample document with XMP metadata."; } } function myGetSlugBounds(myDocument, myPage, mySlugOffset
  • Adobe 0046100128056 | Scripting Guide - Page 123
    CHAPTER 8: Events Sample Selection Event Listeners 123 #targetengine "session" //Adds an event listener that performs a preflight check on a document //before printing. If the preflight check fails, the script cancels //the print job. main(); function main(){ var myEventListener = app.
  • Adobe 0046100128056 | Scripting Guide - Page 124
    the event handler checks the selection to see whether the Registration swatch has been applied. (Accidental application of the Registration swatch can cause problems at your commercial printer.) If the Registration swatch has been applied, the script asks whether the change was intentional. For the
  • Adobe 0046100128056 | Scripting Guide - Page 125
    CHAPTER 8: Events Sample onIdle Event Listener 125 can be used to automatically execute a script when InDesign/InCopy is idle. Its event target is IdleTask, and its event object is IdleEvent. The sleep property of the idle task is the amount of time that elapses before InDesign calls the task
  • Adobe 0046100128056 | Scripting Guide - Page 126
    CHAPTER 8: Events Sample onIdle Event Listener 126 #targetengine "session" main(); function main() { if (app.idleTasks.length == 0) { alert("There is no idle task."); } else { var myIdleTaskName = "my_idle_task"; var myIdleTask = app.idleTasks.itemByName(myIdleTaskName); if (myIdleTask != null) {
  • Adobe 0046100128056 | Scripting Guide - Page 127
    CHAPTER 8: Events Sample onIdle Event Listener 127 #targetengine "session" main(); function main() { var length = app.idleTasks.length; if (length == 0) { alert("There is no idle task."); } else { var str = ""; for (var i = 0; i < length; i++) { var myIdleTask = app.idleTasks.item(i); str += "idle
  • Adobe 0046100128056 | Scripting Guide - Page 128
    are presented in order of complexity, starting with very simple scripts and building toward more complex operations. We assume you already read Adobe InDesign CS5 Scripting Tutorial and know how to create, install, and run a script. Understanding the Menu Model The InDesign menu-scripting model
  • Adobe 0046100128056 | Scripting Guide - Page 129
    CHAPTER 9: Menus Understanding the Menu Model 129 application menuActions menuAction area checked enabled eventListeners id index label name events parent title scriptMenuActions scriptMenuAction same as menuAction eventListener eventListener ... event event ... To create a list (as a text file)
  • Adobe 0046100128056 | Scripting Guide - Page 130
    CHAPTER 9: Menus Understanding the Menu Model 130 var myMenu; //Open a new text file. var myTextFile = File.saveDialog("Save Menu Action Names As", undefined); //If the user clicked the Cancel button, the result is null. if(myTextFile != null){ //Open the file with write access. myTextFile.open
  • Adobe 0046100128056 | Scripting Guide - Page 131
    CHAPTER 9: Menus Running a Menu Action from a Script 131 var myString = ""; var myMenuAction = app.menuActions.item("Convert to Note"); var myKeyStrings = app.findKeyStrings(myMenuAction.name); if(myKeyStrings.constructor.name == "Array"){ for(var myCounter = 0; myCounter < myKeyStrings.length;
  • Adobe 0046100128056 | Scripting Guide - Page 132
    CHAPTER 9: Menus Menus and Events 132 var myMainMenu = app.menus.item("Main"); var myTypeMenu = myMainMenu.menuElements.item("Type"); var myFontMenu = myTypeMenu.menuElements.item("Font"); var myKozukaMenu = myFontMenu.submenus.item("Kozuka Mincho Pro "); var mySpecialFontMenu = myMainMenu.
  • Adobe 0046100128056 | Scripting Guide - Page 133
    CHAPTER 9: Menus Working with scriptMenuActions 133 the wording of menu item, or performs other tasks related to the menu. This mechanism is used internally to change the menu listing of available fonts, recent documents, or open windows. Working with scriptMenuActions You can use scriptMenuAction
  • Adobe 0046100128056 | Scripting Guide - Page 134
    CHAPTER 9: Menus A More Complex Menu-scripting Example 134 var myScriptMenuActionNames = app.scriptMenuActions.everyItem().name; //Open a new text file. var myTextFile = File.saveDialog("Save Script Menu Action Names As", undefined); //If the user clicked the Cancel button, the result is null. if(
  • Adobe 0046100128056 | Scripting Guide - Page 135
    selection contain any graphics? for(var myCounter = 0; myCounter < app.selection.length; myCounter ++){ switch(app.selection[myCounter].constructor.name){ case "PDF": case "EPS": case "Image": myObjectList.push(app.selection[myCounter]); break; case "Rectangle": case "Oval": case "Polygon": if(app
  • Adobe 0046100128056 | Scripting Guide - Page 136
    selection contain any graphics? for(var myCounter = 0; myCounter < app.selection.length; myCounter ++){ switch(app.selection[myCounter].constructor.name){ case "PDF": case "EPS": case "Image": myObjectList.push(app.selection[myCounter]); break; case "Rectangle": case "Oval": case "Polygon": if(app
  • Adobe 0046100128056 | Scripting Guide - Page 137
    CHAPTER 9: Menus A More Complex Menu-scripting Example 137 break; //XMP description case 2: try{ myLabel = myLink.linkXmp.description; } catch(myError){ myLabel = "No description available."; } break; //XMP author case 3: try{ myLabel = myLink.linkXmp.author } catch(myError){ myLabel = "No author
  • Adobe 0046100128056 | Scripting Guide - Page 138
    CHAPTER 9: Menus A More Complex Menu-scripting Example 138 ({editValue:24, editUnits:MeasurementUnits.points}); } } //Text frame offset with(dialogRows.add()){ with(dialogColumns.add()){ staticTexts.add({staticLabel:"Label Offset", minWidth:myLabelWidth}); } with(dialogColumns.add()){ var
  • Adobe 0046100128056 | Scripting Guide - Page 139
    CHAPTER 9: Menus A More Complex Menu-scripting Example 139 myAddLabel(myGraphic, myLabelType, myLabelHeight, myLabelOffset, myLabelStyle, myLayerName); } app.documents.item(0).viewPreferences. horizontalMeasurementUnits = myOldXUnits; app.documents.item(0).viewPreferences. verticalMeasurementUnits
  • Adobe 0046100128056 | Scripting Guide - Page 140
    10 Working with Preflight Preflight is a way to verify that you have all required files, fonts, assets (e.g., placed images and PDF files), problem. It can be run in the background as you work. This chapter demonstrates how to interact with the preflight system using scripting. For illustration
  • Adobe 0046100128056 | Scripting Guide - Page 141
    CHAPTER 10: Working with Preflight Exploring Preflight Profiles 141 Listing preflight rules This script fragment shows how to list all preflight rules in a profile. For the complete
  • Adobe 0046100128056 | Scripting Guide - Page 142
    CHAPTER 10: Working with Preflight Importing a Preflight Profile 142 else if (type == RuleDataType.OBJECT_DATA_TYPE) { return "Object"; } else if (type == RuleDataType.REAL_DATA_TYPE) { return "Real"; } else if (type == RuleDataType.
  • Adobe 0046100128056 | Scripting Guide - Page 143
    CHAPTER 10: Working with Preflight Creating a Preflight Profile 143 You also can load a profile them to files, and import them using scripting. This approach avoids the challenges involved with manually adding rules via scripting. Creating a Preflight Profile To create a preflight profile from the
  • Adobe 0046100128056 | Scripting Guide - Page 144
    CHAPTER 10: Working with Preflight Adding Rules 144 //Add a new preflight profile var myProfile = app.preflightProfiles.add(); if (myProfile == null) { alert("The profile did not add successfully"); }
  • Adobe 0046100128056 | Scripting Guide - Page 145
    CHAPTER 10: Working with Preflight Processing a Profile 145 //Requires the page size to be 8.5in (For the complete script, see ProcessPreflightProfile.) If there are errors, it writes the results to a new PDF file. For an example of the output, see the figure below the script. // Assume there is
  • Adobe 0046100128056 | Scripting Guide - Page 146
    CHAPTER 10: Working with Preflight Custom Rules 146 If you would rather produce a text file, simply name your output file with a .txt extension. Alternately, you may prefer
  • Adobe 0046100128056 | Scripting Guide - Page 147
    CHAPTER 10: Working with Preflight Rule name ADBE_BlankPages ADBE_BleedSlug ADBE_BleedTrimHazard ADBE_CMYPlates ADBE_Colorspace ADBE_ConditionIndicators ADBE_CrossReferences ADBE_FontUsage ADBE_ImageColorManagement ADBE_ImageResolution ADBE_InteractiveContent ADBE_LayerVisibility ADBE_MissingFonts
  • Adobe 0046100128056 | Scripting Guide - Page 148
    CHAPTER 10: Working with Preflight Rule name ADBE_TransparencyUsage ADBE_WhiteOverprint ADBE_BlankPages Data Type Boolean Boolean ADBE_BleedSlug Data Type Real Real Integer Boolean Real Real Real Real Real Real
  • Adobe 0046100128056 | Scripting Guide - Page 149
    CHAPTER 10: Working with Preflight Data Type Real Real Name slug_t_aux tolerance ADBE_BleedTrimHazard Data Type Boolean Real Real Real Real Real Real ADBE_Colorspace Name binding_enabled binding_width live_b
  • Adobe 0046100128056 | Scripting Guide - Page 150
    CHAPTER 10: Working with Preflight ADBE_FontUsage Available Rules 150 Data Type Boolean Boolean Boolean Boolean Boolean Boolean Boolean Boolean Boolean Boolean Name no_ATC no_Bitmap no_CID no_MultipleMaster no_OpenTypeCFF
  • Adobe 0046100128056 | Scripting Guide - Page 151
    CHAPTER 10: Working with Preflight Data Type Real Boolean Real Real ADBE_PageCount Name gray_max_res gray_min_enabled gray_min_res tolerance Data Type Integer Integer Integer Name comparison_type comparison_value comparison_value_aux ADBE_PageSizeOrientation
  • Adobe 0046100128056 | Scripting Guide - Page 152
    CHAPTER 10: Working with Preflight ADBE_SmallText Available Rules 152 Data Type Real Boolean ADBE_SpotColorSetup Name minSize minSize_trap_safe_only Default value 4 false Data Type Boolean Boolean Integer Boolean Name
  • Adobe 0046100128056 | Scripting Guide - Page 153
    sound files that can then be viewed or listened to in exported PDF, SWF, or XFL documents. Movies and sounds in an InDesign document then open the file in a viewer capable of displaying the content (such as Acrobat Reader or a web browser). Scripts can control the playback properties of a sound or
  • Adobe 0046100128056 | Scripting Guide - Page 154
    . Buttons can contain multiple behaviors. The following script fragment shows how to create a simple button that displays the next page in an exported PDF or SWF (for the complete script, refer to SimpleButton). This button makes use of only the Normal state. //Given a page "myPage" and a document
  • Adobe 0046100128056 | Scripting Guide - Page 155
    CHAPTER 11: Creating Dynamic Documents Creating Buttons 155 //Given a page "myPage" in a document "myDocument," containing the colors //"Blue" and "Red"... //Make a button "from scratch." var myButton = myPage.buttons.add({geometricBounds:[72, 72, 144, 144], name:"GoToNextPageButton"}); var
  • Adobe 0046100128056 | Scripting Guide - Page 156
    CHAPTER 11: Creating Dynamic Documents Creating Multistate Objects 156 myClickArrow.paths.item(0).entirePath = [[186, 294],[186,354],[282, 324]]; //Set the behavior for the button. var myMovieStartBehavior = myPlayButton.movieBehaviors.add({movieItem:myFrame.movies.item(0), behaviorEvent:
  • Adobe 0046100128056 | Scripting Guide - Page 157
    CHAPTER 11: Creating Dynamic Documents Creating Multistate Objects 157 //Given a document "myDocument" and a page "myPage" and //four colors "myColorA," "myColorB," "myColorC," and "myColorD"... var myMSO = myPage.multiStateObjects.add({name:"Spinner", geometricBounds:[72, 72, 144, 144]}); //New
  • Adobe 0046100128056 | Scripting Guide - Page 158
    CHAPTER 11: Creating Dynamic Documents Working with Animation 158 var myButton = myPage.buttons.add({geometricBounds:[72, 72, 144, 144]}); myRolloverState = myButton.states.add(); var myRolloverRectangle = myRolloverState.rectangles.add({geometricBounds:[72, 72, 144, 144]}); var
  • Adobe 0046100128056 | Scripting Guide - Page 159
    CHAPTER 11: Creating Dynamic Documents Working with Animation 159 X timingLists, which define the trigger event (page load, page click, and so on) that start the animation. X timingGroups, which associate a page item or series of page items with a specific timing and define the sequence in which
  • Adobe 0046100128056 | Scripting Guide - Page 160
    CHAPTER 11: Creating Dynamic Documents Working with Animation 160 timingTarget, and having the trigger event DynamicTriggerEvents.onPageClick requires five mouse clicks to process all the animations. //Given a document "myDocument" and a page "myPage" and the color "myColorA", //"myColorB", and "
  • Adobe 0046100128056 | Scripting Guide - Page 161
    CHAPTER 11: Creating Dynamic Documents Working with Animation 161 DynamicTriggerEvents.onPageLoad, by DynamicTriggerEvents.onPageClick (for the complete script, refer to MultipleTimingLists). //Given a document "myDocument" and a page "myPage" containg 6 polygons: //"myPolygonA", "myPolygonB", "
  • Adobe 0046100128056 | Scripting Guide - Page 162
    CHAPTER 11: Creating Dynamic Documents Working with Animation 162 //Given a document "myDocument" and a page "myPage" and the color "myColorA"... //Add a page items to animate. var myPolygonA = myPage.polygons.add({fillColor:myColorA, strokeColor:myDocument.swatches.item("None")}); myPolygonA.
  • Adobe 0046100128056 | Scripting Guide - Page 163
    [23,300], [47, 50]]; myOvalB.animationSettings.scaleYArray = [[0, 200], [23,300], [47, 50]]; myOvalB.animationSettings.opacityArray = [[0, 10], [23, 80], [47, 60]]; myOvalB.animationSettings.playsLoop = true; myOvalC.animationSettings.duration = 2; myOvalC.animationSettings.motionPath = myMotionPath
  • Adobe 0046100128056 | Scripting Guide - Page 164
    ++){ myDocument.spreads.item(myCounter).pageTransitionType = PageTransitionTypeOptions.pageTurnTransition; //This page transition option does not support the pageTransitionDirection //or pageTransitionDuration properties. If you chose //PageTransitionTypeOptions.wipeTransition (for example), you
  • Adobe 0046100128056 | Scripting Guide - Page 165
    includes a complete set of features for importing XML data into page layouts, and these features can be controlled using scripting. We assume you already read Adobe InDesign CS5 Scripting Tutorial and know how to create and run a script. We also assume you have some knowledge of XML, DTDs, and XSLT
  • Adobe 0046100128056 | Scripting Guide - Page 166
    CHAPTER 12: XML Scripting XML Elements 166 Scripting XML Elements This section shows how to set XML preferences and XML import preferences, import XML, create XML elements, and add XML attributes. The scripts in this section demonstrate techniques for working with the XML content itself; for
  • Adobe 0046100128056 | Scripting Guide - Page 167
    CHAPTER 12: XML Scripting XML Elements 167 var myDocument = app.documents.add(); var myXMLImportPreferences = myDocument.xmlImportPreferences; myXMLImportPreferences.allowTransform = false; myXMLImportPreferences.createLinkToXML = false; myXMLImportPreferences.ignoreUnmatchedIncoming = true;
  • Adobe 0046100128056 | Scripting Guide - Page 168
    CHAPTER 12: XML Scripting XML Elements 168 Loading XML tags You can import XML tags from an XML file without importing the XML contents of the file. You might want to do this to work out a tag-to-style or style-to-tag mapping before you import the XML data., as shown in the following script
  • Adobe 0046100128056 | Scripting Guide - Page 169
    but can be inserted in an InDesign XML structure for export to other applications. An XML document can contain multiple processing instructions. An XML processing instruction has two parts, target and value. The following is an example: The
  • Adobe 0046100128056 | Scripting Guide - Page 170
    CHAPTER 12: XML Scripting XML Elements 170 var myDocument = app.documents.item(0); var myRootXMLElement = myDocument.xmlElements.item(0); var myXMLElementB = myRootXMLElement.xmlElements.item(1); myXMLElementB.xmlAttributes.add("example_attribute", "This is an XML attribute. It will not appear in
  • Adobe 0046100128056 | Scripting Guide - Page 171
    CHAPTER 12: XML Adding XML Elements to a Layout 171 //Export the entire XML structure in the document. myDocument.exportFile(ExportFormat.xml, File("/c/completeDocumentXML.xml")); //Export a specific XML element and its child XML elements. var myXMLElement = myDocument.xmlElements.item(0).
  • Adobe 0046100128056 | Scripting Guide - Page 172
    CHAPTER 12: XML Adding XML Elements to a Layout 172 var myPage = myDocument.pages.item(0); var myXMLElement = myDocument.xmlElements.item(0); myXMLElement.placeIntoCopy(myPage, [288, 72], myPage.textFrames.item(0), true); To associate an existing page item (or a copy of an existing page item) with
  • Adobe 0046100128056 | Scripting Guide - Page 173
    CHAPTER 12: XML Adding XML Elements to a Layout 173 Mapping tags to styles One of the quickest ways to apply formatting to XML text elements is to use XMLImportMaps, also known as tag-to-style mapping. When you do this, you can associate a specific XML tag with a paragraph or character style. When
  • Adobe 0046100128056 | Scripting Guide - Page 174
    CHAPTER 12: XML Adding XML Elements to a Layout 174 var myDocument = app.documents.item(0); //Create tags that match the style names in the document, //creating an XMLExportMap for each tag/style pair. for(var myCounter = 0; myCounter
  • Adobe 0046100128056 | Scripting Guide - Page 175
    CHAPTER 12: XML Adding XML Elements to a Layout 175 //Create a character style. var myCharacterStyle = myDocument.characterStyles.add(); myCharacterStyle.name = "Emphasis"; myCharacterStyle.fontStyle = "Italic"; //Add XML elements and apply paragraph styles. var myRootXMLElement = myDocument.
  • Adobe 0046100128056 | Scripting Guide - Page 176
    .colors.item("Black"); myTableStyle.startRowFillTint = 25; myTableStyle.endRowFillColor = myDocument.colors.item("Black"); myTableStyle.endRowFillTint = 10; var myCellStyle = myDocument.cellStyles.add(); myCellStyle.fillColor = myDocument.colors.item("Black"); myCellStyle.fillTint = 45 //Add
  • Adobe 0046100128056 | Scripting Guide - Page 177
    .xmlElements.item(0).applyCellStyle(myCellStyle); myTableXMLElement.xmlElements.item(5).applyCellStyle(myCellStyle); myTableXMLElement.xmlElements.item(10).applyCellStyle(myCellStyle); myTableXMLElement.xmlElements.item(15).applyCellStyle(myCellStyle); myTableXMLElement.xmlElements.item(16
  • Adobe 0046100128056 | Scripting Guide - Page 178
    using XML rules. X Create page items based on XML rules. X Restructure data using XML rules. X Use the XML-rules processor. We assume you already read Adobe InDesign CS5 Scripting Tutorial and know how to create and run a script. We also assume you have some knowledge of XML and have read Chapter
  • Adobe 0046100128056 | Scripting Guide - Page 179
    and matches the RuleName; ValidXPathSpecifier is an XPath expression. Later in this chapter, we present a series of functioning XML-rule examples. NOTE: XML rules support a limited subset of XPath 1.0. See "XPath limitations" on page 183." XML-rule sets An XML-rule set is an array of one or more
  • Adobe 0046100128056 | Scripting Guide - Page 180
    the XML-rules processor object built into InDesign's scripting model, Adobe provides a set of functions intended to make the process of this script in conjunction with the AddAttribute tutorial script to troubleshoot XML traversal problems in your own XML documents (you must edit the AddAttribute
  • Adobe 0046100128056 | Scripting Guide - Page 181
    CHAPTER 13: XML Rules Overview 181 Root 1 B 2 9 BA BB 3 4 5 BAA BAB BAC BC 8 6 7 BACA BACB Iteration with __processChildren (assuming a rule that matches every XML element in the structure) is shown in the following figure: Root 9 B 8 6 7 BA BB BC 5 4 3 BAA BAB BAC 2 1
  • Adobe 0046100128056 | Scripting Guide - Page 182
    value + "\r"; return false; } //End of apply function } Root 1 19 2 B 18 14 16 BA 3 5 BB BC 13 15 17 7 BAA BAB 4 6 BAC 8 12 10 BACA BACB 9 11 Changing structure during iteration When an XML-rules processor finds a matching XML element and applies an XML rule, the rule can
  • Adobe 0046100128056 | Scripting Guide - Page 183
    another variable in the script. XPath limitations InDesign's XML rules support a limited subset of the XPath 1.0 specification, specifically including (). X Find PI by target or any; for example, /doc/processing-instruction('foo'). X Find multiple predicates; for example, /doc/para[@font='Courier'][@
  • Adobe 0046100128056 | Scripting Guide - Page 184
    CHAPTER 13: XML Rules Overview 184 X No path specifications in predicates; for example, foo[bar/c]. X No last() function. X No text() function or text comparisons; however, you can use InDesign scripting to examine the text content of an XML element matched by a given XML rule. X No compound
  • Adobe 0046100128056 | Scripting Guide - Page 185
    CHAPTER 13: XML Rules XML Rules Examples 185 XML rules script XML rule XPath condition apply() XML rules XML element glue code __processRuleSet XPath condition XML element XML rule processor XPath evaluation __processChildren XML element XML structure iteration __skipChildren XML Rules
  • Adobe 0046100128056 | Scripting Guide - Page 186
    CHAPTER 13: XML Rules XML Rules Examples 186 //XMLRuleExampleSetup.jsx // main(); function main(){ var myDocument = app.documents.add(); myDocument.xmlImportPreferences.allowTransform = false; myDocument.xmlImportPreferences.ignoreWhitespace = true; var myScriptPath = myGetScriptPath(); var
  • Adobe 0046100128056 | Scripting Guide - Page 187
    CHAPTER 13: XML Rules XML Rules Examples 187 main(); function main(){ if (app.documents.length != 0){ var myDocument = app.documents.item(0); //This rule set contains a single rule. var myRuleSet = new Array (new AddReturns); with(myDocument){ var elements = xmlElements; __processRuleSet(elements.
  • Adobe 0046100128056 | Scripting Guide - Page 188
    CHAPTER 13: XML Rules XML Rules Examples 188 function ProcessDevice(){ this.name = "ProcessDevice"; this.xpath = "/devices/device"; // Define the apply function. this.apply = function(myElement, myRuleProcessor){ with(myElement){ //Add a return character at the end of the XML element.
  • Adobe 0046100128056 | Scripting Guide - Page 189
    CHAPTER 13: XML Rules XML Rules Examples 189 //Adds static text around the "minimum" and "maximum" //XML elements of the "supply_voltage" XML element. function ProcessSupplyVoltage(){ this.name = "ProcessSupplyVoltage"; this.xpath = "/devices/device/supply_voltage"; // Define the apply function.
  • Adobe 0046100128056 | Scripting Guide - Page 190
    CHAPTER 13: XML Rules XML Rules Examples 190 } else{ insertTextAsContent("\r", XMLElementPosition.afterElement); } } return true; } //End of apply function } function ProcessPrice(){ this.name = "ProcessPrice"; this.xpath = "/devices/device/price"; // Define the apply function. this.apply =
  • Adobe 0046100128056 | Scripting Guide - Page 191
    CHAPTER 13: XML Rules XML Rules Examples 191 structure of an XML document are best done using an XSLT file to transform the document before or during XML import into InDesign. The following XML rule script shows how to use the move method to accomplish this. Note the use of the __skipChildren
  • Adobe 0046100128056 | Scripting Guide - Page 192
    XML element contents to XML attributes attached to their parent XML element can be very useful in XML-rule scripting. While the subset of XPath supported by XML rules cannot search the text of an element, it can find elements by a specified attribute value. For the complete script, see AddAttribute
  • Adobe 0046100128056 | Scripting Guide - Page 193
    CHAPTER 13: XML Rules XML Rules Examples 193 main(); function main(){ if (app.documents.length != 0){ var myDocument = app.documents.item(0); var myRuleSet = new Array (new AddAttribute); with(myDocument){ var elements = xmlElements; __processRuleSet(elements.item(0), myRuleSet); } } else{ alert("
  • Adobe 0046100128056 | Scripting Guide - Page 194
    CHAPTER 13: XML Rules XML Rules Examples 194 Applying multiple matching rules When the apply function of an XML rule returns true, the XML-rules processor does not apply any further XML rules to the matched XML element. When the apply function returns false, however, the XML-rules processor can
  • Adobe 0046100128056 | Scripting Guide - Page 195
    "); } myCounter++; } //Do not process the element with any further matching rules. return true; } } } Finding XML elements As noted earlier, the subset of XPath supported by XML rules does not allow for searching the text contents of XML elements. To get around this limitation, you can either use
  • Adobe 0046100128056 | Scripting Guide - Page 196
    CHAPTER 13: XML Rules XML Rules Examples 196 myElement.parent.xmlAttributes.add("part_number", myElement.texts.item(0).contents); return true; } } function FindAttribute(){ this.name = "FindAttribute"; this.xpath = "/devices/device[@part_number = 'DS001']"; this.apply = function(myElement,
  • Adobe 0046100128056 | Scripting Guide - Page 197
    CHAPTER 13: XML Rules XML Rules Examples 197 main(); function main(){ if (app.documents.length != 0){ var myDocument = app.documents.item(0); var myRuleSet = new Array (new FindByFindText); with(myDocument){ var elements = xmlElements; __processRuleSet(elements.item(0), myRuleSet); } } else{ alert
  • Adobe 0046100128056 | Scripting Guide - Page 198
    CHAPTER 13: XML Rules XML Rules Examples 198 //XPath will match on every description in the XML structure. this.xpath = "/devices/device/description"; // Define the apply function. this.apply = function(myElement, myRuleProcessor){ var myFoundItems = myElement.texts.item(0).findGrep(); if(
  • Adobe 0046100128056 | Scripting Guide - Page 199
    :"Bold", leading:12}); myDocument.paragraphStyles.add({name:"Voltage", pointSize:10, leading:12}); myDocument.paragraphStyles.add({name:"DevicePackage", pointSize:10, leading:12}); myDocument.paragraphStyles.add({name:"Price", pointSize:10, leading:12, fontStyle:"Bold"}); var myRuleSet = new Array
  • Adobe 0046100128056 | Scripting Guide - Page 200
    CHAPTER 13: XML Rules XML Rules Examples 200 } function ProcessName(){ this.name = "ProcessName"; this.xpath = "/devices/device/name"; this.apply = function(myElement, myRuleProcessor){ var myDocument = app.documents.item(0); with(myElement){ insertTextAsContent("\r", XMLElementPosition.
  • Adobe 0046100128056 | Scripting Guide - Page 201
    CHAPTER 13: XML Rules XML Rules Examples 201 with(myElement.xmlElements.item(0)){ insertTextAsContent(" to ", XMLElementPosition.afterElement); } with(myElement.xmlElements.item(-1)){ //Add static text to the beginning of the voltage range. insertTextAsContent(" volts", XMLElementPosition.
  • Adobe 0046100128056 | Scripting Guide - Page 202
    CHAPTER 13: XML Rules XML Rules Examples 202 function ProcessPrice(){ this.name = "ProcessPrice"; this.xpath = "/devices/device/price"; this.apply = function(myElement, myRuleProcessor){ var myDocument = app.documents.item(0); with(myElement){ insertTextAsContent("Price: $", XMLElementPosition.
  • Adobe 0046100128056 | Scripting Guide - Page 203
    CHAPTER 13: XML Rules Creating Tables using XML Rules 203 //Creates a new text frame at the top of the page to contain the "type" XML element. function ProcessType(){ this.name = "ProcessType"; this.xpath = "/devices/device/type"; this.apply = function(myElement, myRuleProcessor){ var myDocument =
  • Adobe 0046100128056 | Scripting Guide - Page 204
    utility functions in glue code.jsx, you also can script the XML-rules processor object directly. You might want do this to develop your own support routines for XML rules or to use the XML-rules processor in other ways. When you script XML elements outside the context of XML rules
  • Adobe 0046100128056 | Scripting Guide - Page 205
    CHAPTER 13: XML Rules Scripting the XML-rules Processor Object 205 main(); function main(){ var myXPath = ["/devices/device"]; var myXMLMatches = mySimulateXPath(myXPath); //At this point, myXMLMatches contains all of the XML elements //that matched the XPath expression provided in myXPath.
  • Adobe 0046100128056 | Scripting Guide - Page 206
    14 Track Changes Writers can track, show, hide, accept, and reject changes as a document moves through the writing and editing process. All changes are recorded and visualized to make it easier to review a document. This tutorial shows how to script the most common operations involving tracking
  • Adobe 0046100128056 | Scripting Guide - Page 207
    Track Changes Tracking Changes 207 var myDocument = app.documents.item(0); var myStory = myDocument.stories.item(0); //Story.trackChanges If true, track changes is turned on. if(myStory.trackChanges==true) { var myChangeCount = myStory.changes.length; var myChange = myStory.changes.lastItem(); if(
  • Adobe 0046100128056 | Scripting Guide - Page 208
    Track Changes Preferences for Tracking Changes 208 var myDocument = app.documents.item(0); var myStory = myDocument.stories.item(0); var myChange = myStory.changes.item(0); //ChangeTypes.DELETED_TEXT (Read Only) Deleted text. //ChangeTypes.DELETED_TEXT (Read Only) Deleted text. //ChangeTypes.
  • Adobe 0046100128056 | Scripting Guide - Page 209
    Track Changes Preferences for Tracking Changes 209 //ChangeMarkings.UNDERLINE_SINGLE (Read Only) Underlines changed text. markingForAddedText = ChangeMarkings.OUTLINE; markingForDeletedText = ChangeMarkings.STRIKETHROUGH; markingForMovedText = ChangeMarkings.UNDERLINE_SINGLE;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209

ADOBE
®
INDESIGN
®
CS5
ADOBE INDESIGN CS5
SCRIPTING GUIDE: JAVASCRIPT