Adobe Document Server Developers Guide
Version 6.0
ADOBE SYSTEMS INCORPORATED Corporate Headquarters 345 Park Avenue San Jose, CA 95110-2704 (408) 536-6000 http://www.adobe.com Release
Adobe® Document Server Software Developers’ Kit December 19, 2003 Copyright 2003 Adobe Systems Incorporated. All rights reserved. Adobe® Document Server 6.0 Developers Guide for Sun™ Solaris™ and Microsoft® Windows® If this guide is distributed with software that includes an end user agreement, this guide, as well as the software described in it, is furnished under license and may be used or copied only in accordance with the terms of such license. Except as permitted by any such license, no part of this guide may be reproduced, stored in a retrieval system, or transmitted, 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 agreement. 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 Caslon, Adobe Garamond, Adobe Jenson, Acrobat, Acrobat Reader, FrameMaker, Distiller, GoLive, Illustrator, ImageReady, InDesign, Kozuka Gothic, Kozuka Mincho, Minion, Myriad, Photoshop, PostScript, and XMP are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries. Apple, Mac, Macintosh, Power Macintosh and TrueType are trademarks of Apple Computer, Inc., registered in the United States and other countries. Microsoft, Windows, Windows NT, and OpenType are either a registered trademark or a trademark of Microsoft Corporation in the United States and other countries. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. Products bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems, Inc. Sun, Solaris, Java, Java Applet, Java Servlet, and JavaScript are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. UNIX is a registered trademark of The Open Group. X Window System is a trademark of The Open Group. All other trademarks are the property of their respective owners. © 1989 All Rights Reserved by Proximity Technology Inc. Proximity and Linguibase are registered trademarks of Proximity Technology Inc. The Proximity/Merriam-Webster Database © 1984-1990 Merriam-Webster Inc. © 1990 - All Rights Reserved. This product includes software developed by the Apache Software Foundation (http://www.apache.org). © 1998-2001 The Apache Group. All rights reserved. © 1995-2001 International Business Machines Corporation and others. All rights reserved. © 1990 David Koblas. Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted. This software is provided “as is” without express or implied warranty. © 1994 Anthony Dekker. This product includes code licensed from RSA Security, Inc. Some portions licensed from IBM are available at http://oss.software.ibm.com/icu4J . Copyright© 1990, RSA Data Security, Inc. All rights reserved. License to copy and use this software is granted provided that it is identified as the “RSA Data Security, Inc. MD5 Message-Digest Algorithm” in all material mentioning or referencing this software or function. License is also granted to make and use derivative works provided that such works are identified as ‘derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm’ in all material mentioning or referencing the derived work. RSA Data Security, Inc. makes no representations concerning either the merchantability of this softare or the suitability of this software for any particular purpose. It is provided “as is” without express or implied warranty of any kind. These notices must be retained in any copies of any part of this documenation and/or software. Copyright© 1994-1996 SunSoft Inc. Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL SUNSOFT, INC. OR ITS PARENT COMPANY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the name of SunSoft, Inc. shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without written notice. License Language:ICU License - ICU 1.8.1 and later COPYRIGHT AND PERMISSION NOTICE Copyright (c) 1995-2003 International Business Machines Corporation and others All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, provided that the above copyright notice(s) and this permission notice appear in all copies of the Software and that both the above copyright notice(s) and this permission notice appear in supporting documentation. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of the copyright holder.
2 (1) University of California, Berkeley Copyright© 1990 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, advertising materials, and other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED “AS IS” AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. (2) DJ Delorie Copyright© 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954 This file is distributed under the terms listed in the document “copying.dj”, available from DJ Delorie at the address above. A copy of “copying.dj” should accompany this file; if not, a copy should be available from where this file was obtained. This file may not be distributed without a verbatim copy of “copying.dj”. This file is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. (3) David M. Gay at AT&T The author of this software is David M. Gay. Copyright© 1991 by AT&T. Permission to use, copy, modify, and distribute this software for any purpose without fee is hereby granted, provided that this entire notice is included in all copies of any software which is or includes a copy or modification of this software and in all copies of the supporting documentation for such software. THIS SOFTWARE IS BEING PROVIDED “AS IS”, WITHOUT ANY EXPRESS OR IMPLIED WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. Hewlett-Packard Copyright© 1986 HEWLETT-PACKARD COMPANY To anyone who acknowledges that this file is provided “AS IS” without any express or implied warranty: permission to use, copy, modify, and distribute this file for any purpose is hereby granted without fee, provided that the above copyright notice and this notice appears in all copies, and that the name of Hewlett-Packard Company not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Hewlett-Packard Company makes no representations about the suitability of this software for any purpose. Unless otherwise stated in each remaining newlib file, the remaining files in the newlib subdirectory are governed by the following copyright. Copyright©1994, 1997 Cygnus Solutions. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, advertising materials, and other materials related to such distribution and use acknowledge that the software was developed at Cygnus Solutions. Cygnus Solutions may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED “AS IS” AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF General Terms and Conditions page 9 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Copyright© 1996 Silicon Graphics Computer Systems, Inc. Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting Documentation. Adobe Systems Incorporated, 345 Park Avenue, San Jose, California 95110-2704, 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. 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.
3 4 Contents
Preface ...... 23
Part I: Basics
Chapter 1 Overview of Adobe Document Server...... 27
Product Summary ...... 27 ADS Commands ...... 27 ADS Requests ...... 28 Manipulating Graphics Input...... 28 Manipulating Documents...... 29 Manipulating Metadata ...... 29 Format Summary ...... 30 Input, Output, and Metadata Formats ...... 30 Format Conversions ...... 32 Web-Related Standards and Formats ...... 33
Chapter 2 Invoking ADS ...... 35
Deploying and Invoking ADS ...... 35 The Interface Model ...... 37 The Objects in the Model ...... 37 Interacting with ADS ...... 37 Details of the Objects in the Model...... 39 Server Objects in the APIs...... 39 Requests ...... 40 Results and Responses...... 41 Logging ...... 42 How ADS Handles URIs ...... 43 Base URIs for the APIs ...... 44 Base URIs for the Command Line ...... 44 Base URIs for an ADS Process...... 45 Base URI Summary ...... 46
Adobe Document Server Developers Guide Dec 19, 2003 5 Contents
Chapter 3 ADS Command Basics ...... 47
Overview ...... 47 Content Holders and Types ...... 48 How Content Becomes Current ...... 49 How Content Holders Work ...... 50 Content Types and File Formats ...... 51 Loading Content ...... 53 Specifying Input Data ...... 53 How File Formats Map to Content Types Upon Load...... 55 Converting Content ...... 57 Direct Content Type Conversions ...... 57 Commands That Work on One Content Type but Produce Another ...... 58 Saving Content ...... 59 Determining Where Result Content is Saved...... 59 Naming Results ...... 60 Basic File Saving ...... 61 Saving to Optimized Formats ...... 63 Automatic File Saving ...... 64 Referenced Attributes Values ...... 65 General Commands ...... 66
Chapter 4 Working with File Metadata ...... 67
Overview of Metadata...... 67 Metadata and Content Types ...... 67 Creating a Custom Metadata Schema ...... 68 Working with Metadata in ADS ...... 69 Extracting Metadata from Loaded Content...... 69 Modifying Metadata in Loaded Content ...... 74 Saving Files with Metadata ...... 77 Transformations of Metadata Formats...... 78 Supported Metadata Formats ...... 78 Metadata Namespaces ...... 80 Metadata Aliases ...... 81 Automatic Metadata Updates ...... 82 Resolving Metadata Inconsistency ...... 83
6 Dec 19, 2003 Adobe Document Server Developers Guide Contents
Part II: Graphics
Chapter 5 Basic Image Manipulations ...... 87
Overview ...... 87 Sizing and Cropping Images ...... 88 Changing the Canvas Size ...... 88 Changing Image Size...... 90 Layer Manipulations ...... 95 Referring to Layers ...... 95 Setting Layer Visibility and Opacity...... 96 Flattening Layers ...... 97 Layers in Images from Other Formats ...... 98 Layer and Layer Set Support in Versions of Photoshop ...... 98 Working with Color...... 99 Manipulating Color Profiles Directly ...... 99 Color Profiles in Other Operations ...... 101 Color Space Support in ADS ...... 102 Modifying Image Data...... 103 Changing Image Orientation...... 103 Replacing All or Part of an Image ...... 104 Replacing Text in an Image ...... 106 Changing Colors in an Image ...... 107 Controlling Visual Quality...... 108 Accessing Raster Content...... 109 Retrieving Image Information ...... 109 Setting Elements of an Image ...... 110 Treating PostScript and PDF Content as Images ...... 112 Saving Optimized Files ...... 112 Tuning Optimization Settings Outside ADS ...... 112 Tuning Optimization Settings in ADS ...... 113 Balancing Quality and Size in Optimized Image Files ...... 115 Changing the Image File Size ...... 115 Saving Metadata with Optimized Files...... 116 Custom Color Palettes in Optimized Files ...... 117 Saving Dynamic PSD and Animated GIFs ...... 117 Legacy File Limitations ...... 118
Adobe Document Server Developers Guide Dec 19, 2003 7 Contents
Chapter 6 Changing Text in Images ...... 119
Changing Text in Images ...... 119 Replacing Text in Raster Content ...... 120 Replacing Text in an SVG Text Flow...... 121 Changing Text Attributes in Text Flows ...... 123 The Structure of a Text Flow ...... 123 Setting Text Characteristics...... 127
Chapter 7 Replacing Variables in SVG and PSD Files ...... 131
Overview of Variable Binding and Replacement ...... 131 Automatic Variable Replacement...... 133 Replacing Variables Explicitly ...... 134 Specifying Replacement Data ...... 136 Variable Replacement Error Behavior ...... 136 SVG Variable Replacement Syntax ...... 136 PSD Variable Replacement Syntax ...... 141
Chapter 8 Operations Specific to SVG Files...... 145
Overview ...... 145 Foreign Objects ...... 145 Graph Foreign Object ...... 146 Text Flow Foreign Object ...... 147 Image Replacement Foreign Objects ...... 147 SVG Font Considerations ...... 148 Embedded Fonts in SVG...... 148 Resolving Font References within SVG...... 148 Illustrator SVG Template Tips ...... 149 Naming Shapes and Layers ...... 149 Using Crop Marks ...... 150 Saving SVG for ADS Compatibility ...... 150 Converting SVG to Raster...... 151 Converting SVG to PDF ...... 151
8 Dec 19, 2003 Adobe Document Server Developers Guide Contents
Chapter 9 Creating Dynamic Graphs in SVG Files ...... 153
Overview ...... 154 A Working Sample ...... 155 Graphing Basics ...... 158 Parts of a Graph ...... 158 Basic Graph Types...... 158 Graph Objects in ADS ...... 159 Graph Formatting Overview ...... 160 Graph Layout...... 160 Stacking Options ...... 161 Graph Type-Specific Formatting Options ...... 161 Specific Graph Types ...... 162 ADS Graphing Features Not Supported by Illustrator ...... 163 General Graph Layout ...... 163 Legends ...... 164 String Substitutions in Axis and Legend Labels ...... 165 Ticks and Labels ...... 165 Axes ...... 165 Maps ...... 165 Transformations...... 166 ADS Features Applicable to All Graph Types ...... 166 Stacking and Normalizing ...... 166 Accumulating Graph Points ...... 167 Multiple Graph Descriptions ...... 167 ADS Graph Features by Graph Type ...... 167 Bar Graph Features ...... 167 Point Graph Features...... 168 Editing Exported Templates ...... 168 Data Sets ...... 169 The Impact of Maps on Graph Data ...... 169 Properties for Graph Data...... 171 XML Representation of Graph Data ...... 172 The Data Element ...... 172 Abbreviated Graph Data Syntax...... 178 Formatting a Graph ...... 179 Graphing Data Columns ...... 181 Major and Minor Data Columns ...... 181 Sample Graph Format ...... 184
Adobe Document Server Developers Guide Dec 19, 2003 9 Contents
Chapter 9 Creating Dynamic Graphs in SVG Files (Continued)
Graph Transformations (Xforms) ...... 186 The what and which Elements...... 186 Graph Designs and the symbol Element ...... 188 String Substitutions ...... 189 Strict and Lenient Graphing Modes ...... 192 Graph and XML Examples ...... 192 SVG Template ...... 192 Polar Pie Graph ...... 194 Accumulation and Multiple Graph Descriptions ...... 197 Applying a New Data Element ...... 200 String-Labelled Minor Axis ...... 201 Graph with Conflicting Data ...... 204 Applying a New Format ...... 207 Graph Design ...... 209 Graphing Template Guidelines ...... 213
Part III: Documents
Chapter 10 Creating PDF Files from XSL-FO ...... 217
Overview ...... 217 Supported Elements and Attributes ...... 218 Formatting With a FrameMaker Template ...... 219 Identifying the Template ...... 219 Defining the Master Pages ...... 221 Defining Formats ...... 222 Formatting the XSL-FO Content ...... 223 Verifying the Formatting Results ...... 224 Creating a Table of Contents...... 225 Creating Tagged PDF Documents ...... 228 Creating Running Headers and Footers ...... 229 Development Considerations ...... 230
10 Dec 19, 2003 Adobe Document Server Developers Guide Contents
Chapter 10 Creating PDF Files from XSL-FO (Continued)
Formatting Without a FrameMaker Template ...... 232 Defining the Master Pages ...... 232 Formatting Text ...... 234 Using Leaders and Rules ...... 235 Creating Running Headers and Footers ...... 236 Balancing Text Across Columns ...... 237 Generating Page # of ## Folios...... 238 Common Formatting Tasks ...... 239 Referencing Other Content Holders ...... 239 Embedding Graphics...... 239 Defining Variables ...... 240 Specifying XMP Metadata...... 242
Chapter 11 Controlling Document Security ...... 245
Encrypting PDF Documents ...... 245 Encryption Passwords ...... 246 Encryption Examples...... 248 Decrypting PDF Documents ...... 249 Usage Rights ...... 251 Setting Usage Rights ...... 251 Usage Rights in Encrypted Documents ...... 253 Retrieving Usage Rights ...... 255
Chapter 12 Manipulating PDF Features ...... 257
Annotations ...... 257 Annotation Types that ADS Supports ...... 257 Comments ...... 261 Links ...... 266 Bookmarks ...... 269 Exporting Bookmarks ...... 270 Thumbnails...... 271 Updating Thumbnails ...... 271 Deleting Embedded Thumbnails ...... 272 File Attachments ...... 273 Importing File Attachments ...... 274 Exporting File Attachments ...... 276 Deleting File Attachments ...... 277
Adobe Document Server Developers Guide Dec 19, 2003 11 Contents
Chapter 13 Working with PDF Form Fields ...... 279
Overview ...... 279 Filling In Form Field Data ...... 281 Setting Text Field Values Directly ...... 281 Importing and Exporting Form Data ...... 281 Controlling Form Field Appearance ...... 283 Controlling Field Accessibility ...... 286 Controlling the Visibility of a Form Field...... 286 Controlling Write Access for a Form Field ...... 287 Flattening Form Fields ...... 287 Deleting Form Fields ...... 289
Chapter 14 Manipulating Pages and Documents ...... 291
Deleting Pages ...... 292 Adding Pages ...... 294 Forcing an Even Number of Pages ...... 294 Spawning Pages from Templates ...... 294 Combining Documents ...... 296 Inserting One Document into Another ...... 296 Combining Multiple Documents into One ...... 298 Creating and Inserting a Table of Contents ...... 303 Changing Document Layout...... 306 Rotating Pages...... 306 Comparing the Overlay Commands ...... 307 Applying Page Overlays ...... 308 Applying Template Overlays ...... 311 Renumbering Page Labels ...... 315
Chapter 15 Converting and Saving PDF Documents ...... 319
Overview ...... 319 Converting Between Document Formats...... 320 Converting Between PDF and Image Formats ...... 321 Saving Optimized PDF Content ...... 322
Appendix A Example-to-Sample Mapping ...... 323
Index ...... 331
12 Dec 19, 2003 Adobe Document Server Developers Guide List of Figures
Figure 2.1 Deployment and invocation choices for ADS ...... 36 Figure 6.1 XML structure of text flows in Raster and SVG content ...... 123 Figure 9.1 A graph template created in Illustrator ...... 155 Figure 9.2 The Illustrator Variables palette ...... 156 Figure 9.3 A graph template with variables inserted ...... 157 Figure 9.4 Sample sales data set ...... 169 Figure 9.5 Sample grades data set ...... 170 Figure 9.6 Command line variable substitution ...... 179 Figure 9.7 Sample contractor data set ...... 183 Figure 9.8 Polar pie graph ...... 194 Figure 9.9 Multiple graph description, accumulation, and substitution ...... 197 Figure 9.10 Applying a new data element ...... 200 Figure 9.11 Minor axis with string labels ...... 201 Figure 9.12 Graphing conflicting data points separately ...... 204 Figure 9.13 New graph format ...... 207 Figure 9.14 Interstate graph design ...... 209 Figure 12.1 The XML schema for links in PDF content ...... 267
Adobe Document Server Developers Guide Dec 19, 2003 13 List of Figures
14 Dec 19, 2003 Adobe Document Server Developers Guide List of Tables
Table 1.1 Input file formats allowed by ADS ...... 30 Table 1.2 Output file formats produced by ADS ...... 31 Table 1.3 Metadata formats supported and preserved by ADS ...... 32 Table 1.4 Direct content type conversions supported by ADS ...... 32 Table 2.1 Deployment and invocation choices for ADS ...... 35 Table 2.2 Details of invocation choices for invoking ADS ...... 36 Table 2.3 The object model of the ADS interfaces ...... 37 Table 2.4 Steps involved in interacting with ADS ...... 38 Table 2.5 Kinds of server objects in the APIs ...... 40 Table 2.6 The kinds of information in an ADS request ...... 41 Table 2.7 Log levels and their meaning ...... 42 Table 2.8 Supported URI schemes ...... 44 Table 2.9 Base URIs for the ADS interfaces ...... 46 Table 3.1 How content types relate to input and output formats ...... 52 Table 3.2 Specifying input data sources in the loadContent command ...... 54 Table 3.3 Loading file data with the loadContent command ...... 55 Table 3.4 Direct content type conversions ...... 57 Table 3.5 Commands that work on one content type and produce another ...... 58 Table 3.6 Determining the result location ...... 59 Table 3.7 Saving content with the saveContent command ...... 61 Table 3.8 Saving content with the saveOptimized command ...... 63 Table 3.9 File extensions used by the saveOptimized command ...... 63 Table 4.1 Supported metadata formats ...... 79 Table 4.2 Preregistered namespaces ...... 80 Table 4.3 Metadata fields modified by ADS ...... 82 Table 4.4 Metadata format precedence for file types ...... 83 Table 5.1 Color space support for image formats ...... 102 Table 5.2 Photoshop feature introductions ...... 118 Table 5.3 ImageReady feature introductions ...... 118 Table 5.4 Illustrator feature introductions ...... 118 Table 5.5 GoLive feature introductions ...... 118 Table 6.1 Summary of elements and attributes in PSD and SVG text flows ...... 125
Adobe Document Server Developers Guide Dec 19, 2003 15 List of Tables
Table 9.1 Allowed string substitutions ...... 190 Table 12.1 Annotation types and operations supported by ADS ...... 258 Table 13.1 Form field properties you can change in ADS ...... 280 Table 14.1 Comparing the overlayPages and overlayTemplates commands ...... 307 Table A.1 Examples in this document that map to working samples ...... 323
16 Dec 19, 2003 Adobe Document Server Developers Guide List of Examples
Example 3.1 Using a content reference to select an image at run time ...... 66 Example 4.1 Metadata from IPTC format ...... 70 Example 4.2 Metadata from EXIF format ...... 72 Example 4.3 XMP Metadata in a PDF file ...... 73 Example 4.4 Modifying a metadata property ...... 74 Example 4.5 Creating and adding to a structured property ...... 75 Example 4.6 Streaming in replacement metadata in the importMetadata command ...... 76 Example 4.7 Loading replacement metadata from a file ...... 76 Example 4.8 Copying metadata from one file to another...... 77 Example 4.9 Saving an optimized image with a new metadata property...... 78 Example 5.1 Increasing canvas size by adding a border ...... 89 Example 5.2 Trimming an image ...... 89 Example 5.3 Applying a clipping path...... 90 Example 5.4 Making successive size modifications on the same image...... 91 Example 5.5 Changing the resolution of an image ...... 91 Example 5.6 The effects of attempted size changes on different images ...... 93 Example 5.7 Resizing an image and sharpening edges ...... 95 Example 5.8 Setting layer and layer-set visibility ...... 97 Example 5.9 Setting layer opacity ...... 97 Example 5.10 Converting image data to a color profile...... 101 Example 5.11 Rotating an image ...... 103 Example 5.12 Replacing pixels to add a product shot to an image ...... 105 Example 5.13 Duplicating one pixel layer out of several layers ...... 105 Example 5.14 Applying a layer effect by replacing pixels...... 105 Example 5.15 Replacing a color overlay in an image layer ...... 107 Example 5.16 Automatically adjusting contrast in an image ...... 108 Example 5.17 Using the set command to change copyright information for an image ...... 111 Example 5.18 Copying a value from one Raster content holder to another ...... 111 Example 5.19 Setting an optimization attribute ...... 113 Example 5.20 Changing the preferred optimization format with set ...... 114 Example 5.21 Choosing an optimization format automatically ...... 114 Example 5.22 Adjusting the quality of an optimized file ...... 115
Adobe Document Server Developers Guide Dec 19, 2003 17 List of Examples
Example 5.23 Creating a smaller image file ...... 116 Example 6.1 Replacing all text in a layer ...... 120 Example 6.2 Replacing specific text in a layer ...... 120 Example 6.3 Replacing the automatic text variable value ...... 121 Example 6.4 Replacing text in an SVG text flow...... 122 Example 6.5 Replacing an entire text flow in SVG content ...... 122 Example 6.6 Changing a font size ...... 128 Example 6.7 Changing the fill color for text ...... 128 Example 6.8 Changing the overlay color in a text layer ...... 128 Example 6.9 Replacing an entire text flow in Raster content ...... 129 Example 6.10 Replacing text flow attributes in SVG content ...... 130 Example 7.1 Automatic variable replacement on load ...... 134 Example 7.2 Automatic variable replacement from the command line ...... 134 Example 7.3 Loading multiple data sets for a single template file ...... 135 Example 7.4 Streaming in replacement data...... 135 Example 7.5 Basic variable replacement ...... 137 Example 7.6 Replacing a visibility variable ...... 138 Example 7.7 Replacing an image variable with an image file reference...... 138 Example 7.8 Replacing an image variable with embedded image data...... 138 Example 7.9 Replacing a graph variable ...... 139 Example 7.10 Abbreviated graph syntax data...... 140 Example 7.11 Replacing text using a text variable ...... 140 Example 7.12 Replacing text attributes using a text variable ...... 140 Example 7.13 Replacing a visibility variable ...... 141 Example 7.14 Replacing a text variable ...... 142 Example 7.15 Replacing a pixel variable using a file reference ...... 142 Example 7.16 Replacing a pixel variable with an embedded image ...... 142 Example 7.17 Replacing the default text variable ...... 143 Example 9.1 XML structure of the switch element ...... 159 Example 9.2 The values element ...... 172 Example 9.3 The propertyRow element...... 173 Example 9.4 A property element that defines units ...... 173 Example 9.5 An explicit map element ...... 174 Example 9.6 The globalMap element ...... 174 Example 9.7 A complete data element ...... 174 Example 9.8 Mapped values for data ...... 175
18 Dec 19, 2003 Adobe Document Server Developers Guide List of Examples
Example 9.9 A generated map ...... 176 Example 9.10 A data element with an explicit map ...... 176 Example 9.11 A data element with an implicit map ...... 177 Example 9.12 Command line variable substitution ...... 178 Example 9.13 The basic structure of the format element...... 180 Example 9.14 Graphing conflicting values separately...... 183 Example 9.15 A complete graph element for a bar graph ...... 184 Example 9.16 Changing point markers with the what element...... 186 Example 9.17 Changing all point markers for the second series ...... 187 Example 9.18 Changing point markers for the first cluster...... 187 Example 9.19 Changing all point markers ...... 187 Example 9.20 Set operations on what elements ...... 187 Example 9.21 A symbol definition for a graph design...... 189 Example 9.22 Basic string substitution ...... 189 Example 9.23 String substitution with a global units property ...... 189 Example 9.24 Column-specific substitution of a units property ...... 189 Example 9.25 Map string substitution ...... 190 Example 9.26 SVG template for samples ...... 193 Example 9.27 XML load and save...... 193 Example 9.28 XML code for a pie graph ...... 194 Example 9.29 XML code for the multiple graph figure ...... 197 Example 9.30 XML code for the new data element figure ...... 200 Example 9.31 XML code for the minor axis with string labels figure...... 201 Example 9.32 XML code for the conflicting data points figure ...... 204 Example 9.33 XML code for the new format element figure...... 208 Example 9.34 XML code for the Interstate Graph Design figure ...... 209 Example 10.1 Running headers and footers with a FrameMaker template...... 229 Example 10.2 Using ext-fo:fragment-root ...... 231 Example 10.3 Command file without a FrameMaker template ...... 232 Example 10.4 Basic XSL-FO document with a single page master ...... 232 Example 10.5 XSL-FO document with different regions ...... 233 Example 10.6 Running headers and footers without a FrameMaker template ...... 236 Example 10.7 Balancing text across columns ...... 237 Example 10.8 Generating page # of ## folios ...... 238 Example 10.9 Embedding graphics in an XSL-FO document ...... 240 Example 10.10 Defining variables in an XSL-FO document ...... 241
Adobe Document Server Developers Guide Dec 19, 2003 19 List of Examples
Example 10.11 XMP metadata in XSL-FO using fo:root ...... 242 Example 10.12 XMP metadata in XSL-FO using ext-fo:fragment-root...... 243 Example 11.1 Encrypting a PDF document with an open password...... 248 Example 11.2 Encrypting a PDF document with a master password and permissions ...... 248 Example 11.3 Encrypting a PDF file with permissions and both passwords ...... 249 Example 11.4 Decrypting a PDF document with a master password ...... 250 Example 11.5 Decrypting a PDF document with an open password ...... 250 Example 11.6 Enabling all usage rights ...... 252 Example 11.7 Disabling all usage rights ...... 253 Example 11.8 Setting usage rights and encryption permissions ...... 254 Example 11.9 Setting usage rights and resetting encryption ...... 254 Example 11.10 Getting usage rights ...... 255 Example 12.1 Exporting comments in the FDF format ...... 262 Example 12.2 Exporting comments in the XFDF format ...... 262 Example 12.3 Importing comments in XFDF format...... 262 Example 12.4 Merging comments from one source ...... 263 Example 12.5 Merging comments from multiple sources ...... 263 Example 12.6 Deleting all comments ...... 264 Example 12.7 Deleting comments by author ...... 264 Example 12.8 Deleting a specific type of comment ...... 265 Example 12.9 Deleting comments before a particular date ...... 265 Example 12.10 Deleting comments after a particular date ...... 265 Example 12.11 Deleting comments in a particular date range ...... 265 Example 12.12 Deleting comments by multiple authors...... 266 Example 12.13 Exporting links ...... 268 Example 12.14 Deleting links ...... 269 Example 12.15 Exporting bookmarks...... 270 Example 12.16 Updating thumbnails ...... 272 Example 12.17 Deleting thumbnails ...... 273 Example 12.18 Importing data for a file attachment from a content holder...... 275 Example 12.19 Importing data for a file attachment from an external file ...... 275 Example 12.20 Exporting a file attachment into a content holder...... 276 Example 12.21 Exporting a file attachment into an external file ...... 277 Example 12.22 Deleting a file attachment ...... 277 Example 13.1 Providing values for text form fields directly ...... 281 Example 13.2 Exporting form data to FDF format ...... 282
20 Dec 19, 2003 Adobe Document Server Developers Guide List of Examples
Example 13.3 Exporting form data to XFDF format ...... 282 Example 13.4 Importing form data ...... 283 Example 13.5 Exporting and importing together ...... 283 Example 13.6 Changing the appearance of a form field ...... 284 Example 13.7 Changing the style of a check box or radio button ...... 285 Example 13.8 Replacing a button’s icon and caption ...... 285 Example 13.9 Hiding a form field...... 286 Example 13.10 Restricting write access for form fields ...... 287 Example 13.11 Flattening all form fields with the flattenFormFields command ...... 288 Example 13.12 Flattening all form fields with the flattenForm command ...... 288 Example 13.13 Flattening certain form fields by inclusion...... 288 Example 13.14 Flattening certain form fields by exclusion ...... 289 Example 13.15 Deleting specific form fields...... 289 Example 13.16 Deleting all form fields ...... 289 Example 14.1 Deleting the first page of a document ...... 292 Example 14.2 Deleting the last page of a document ...... 292 Example 14.3 Deleting a specified range of pages...... 293 Example 14.4 Deleting discontiguous pages ...... 293 Example 14.5 Deleting all but one page ...... 293 Example 14.6 Forcing an even number of pages ...... 294 Example 14.7 Appending a spawned page ...... 295 Example 14.8 Appending one document to another ...... 297 Example 14.9 Prepending one document to another ...... 297 Example 14.10 Inserting pages before a specified page ...... 298 Example 14.11 Inserting pages after a specific page ...... 298 Example 14.12 Assembling multiple documents ...... 300 Example 14.13 Creating new root bookmarks during assembly ...... 301 Example 14.14 Specifying an alias to resolve former references ...... 302 Example 14.15 Inserting a table of contents into an existing PDF document ...... 305 Example 14.16 Inserting a table of contents in an assembled document ...... 305 Example 14.17 Rotating one page...... 306 Example 14.18 Rotating an entire document ...... 307 Example 14.19 Overlaying a single page...... 309 Example 14.20 Overlaying multiple pages ...... 309 Example 14.21 Skipping pages in the overlay document ...... 309 Example 14.22 Underlaying a page ...... 310
Adobe Document Server Developers Guide Dec 19, 2003 21 List of Examples
Example 14.23 Overlaying form fields and annotations ...... 310 Example 14.24 Applying a transform to an overlay page ...... 311 Example 14.25 Overlaying multiple templates ...... 314 Example 14.26 Renumbering page labels ...... 316 Example 14.27 Renumbering page labels after assembling a new document ...... 317 Example 15.1 Converting PDF to EPS ...... 320 Example 15.2 Converting PostScript to PDF ...... 320 Example 15.3 Converting a PDF document to TIFF format...... 321 Example 15.4 Saving a Web-optimized PDF document...... 322
22 Dec 19, 2003 Adobe Document Server Developers Guide Preface
Introduction Adobe® Document Server (ADS) is a dynamic publishing platform that extends the distinctive competence of Adobe in imaging, static and animated graphics, and page layout to the server infrastructure. ADS allows the extension of current workflow for dynamic HTML (HyperText Markup Language) to include visually rich images and graphics, as well as dynamic generation, manipulation, and combination of PDF files from a variety of sources. Purpose This guide contains information to guide programmers in using the ADS commands and in submitting requests to ADS. It contains some background discussion of basic concepts upon which the command language and the invocation interfaces are based, and provides details for writing commands that manipulate image and document data.
NOTE: "AlterCast" was the name of the previous version of this product. References to the name "AlterCast" still appear in both the product and the documentation. Such references are valid and required for the product to function correctly. Intended Audience The audience for this manual is programmers or other technical personnel who need to write commands or submit requests to ADS. Familiarity with XML (eXtensible Markup Language) is assumed for command set construction. Programmers preparing code to submit requests to ADS from one of the APIs or directly to the Web service are assumed to have some experience with Java, Perl, or COM programming, or with WSDL–capable tools for constructing Web service requests. Some familiarity with Illustrator®, Photoshop®, ImageReady®, Acrobat®, and FrameMaker®, and file formats that these applications use such as SVG, PSD, PDF, and MIF, is also assumed. Organization of This Guide This guide contains three parts. Part I contains general information about the architecture of the product and its general capabilities. Part II contains specific guidance for using the commands that manipulate images. Part III contains specific guidance for using the commands that manipulate document files. See the Table of Contents for detailed organizational information. Related Documents This guide is most useful when used in conjunction with the following references: ● Adobe Document Server Command Reference: Provides a complete reference for the XML commands that implements ADS functionality.
Adobe Document Server Developers Guide Dec 19, 2003 23 Preface
● Adobe Document Server API Reference: Provides a reference for the interfaces used to invoke ADS, including the Java, Perl, and COM APIs, the Web service interface, and the command line interface. Explains how to handle the information received in response. ● Adobe Document Server XML Grammars Reference: Explains how ADS uses and supports XML formats and protocols. Includes reference information for formats and grammars that ADS uses, defines, or extends. Other related documents are: ● Installation and Configuration Guide: Contains installation instructions, configuration requirements, and administrative guidelines for ADS. ● Adobe Document Server Command Quick Reference: Provides brief syntax statements for the ADS XML commands. ● Adobe Document Server 6.0 for Reader Extensions User Guide: Explains how to use and administer the Web application that can enable interactive features in PDF documents. Notational Conventions This document uses typefaces to identify the characteristics of text. These typefaces and the characteristics they imply are described below. To convey additional information, this document may also apply color and underlining to words or phrases that use the typefaces described above. Such use is described below:
Item Use and examples
File names are shown in Courier font. /psd/stoplight.psd
Code items within plain text are shown in Courier The loadContent command font. The getName method
Code examples set off from plain text are shown in Syntax: Courier font.
Document titles, new terms, and variables or other Adobe Document Server Developers Guide placeholders within code are designated by an italic These translation methods are known as font. rendering intents because... in="contentName"
Documentation Problems If you discover any errors in or have any problems with this documentation, please e-mail us at: [email protected] Please describe the error or problem as completely as possible and give us the document title and the page number or page range.
24 Dec 19, 2003 Adobe Document Server Developers Guide Part I
Basics
Adobe Document Server Developers Guide Dec 19, 2003 25 26 Dec 19, 2003 Adobe Document Server Developers Guide Overview of Adobe Document 1 Server
This chapter provides a very general overview of the architecture of Adobe Document Server (ADS), how it works, what file formats it supports, and the underlying standards, technologies, and protocols that it uses. The chapter contains the following sections:
Product Summary starting on page 27 Format Summary starting on page 30 Web-Related Standards and Formats starting on page 33
Product Summary
ADS provides you with functionality you can use to programmatically request a particular set of operations on images and documents. This functionality falls into two main areas: specifying what manipulations ADS should perform, and invoking ADS to perform those manipulations.
ADS Commands ADS provides an XML command language that you use to operate on input data you provide. These commands provide a wide range of manipulations, allowing you to: ● Modify, add to, and combine input data in various ways. ● Replace variables within data of certain types. ● Add data from XML sources and extract information in XML format. ● Modify metadata contained in the input. ● Convert between file formats; for example, from one image format to another, or between image and document formats. You create command sets (in files or other language constructs such as strings) that contain a series of these commands. These commands instruct ADS to load input data and perform specific operations on it. After the desired transformations are done, you can save the results in one of several ways. You can transform a single input file in a number of ways, creating multiple result files from a single input. You can also provide the same input file to the same set of commands, but use different associated data, such as variable replacement data, each time, resulting in a number of different result files from a single input file. In the latter case, input files are also sometimes called templates.
Adobe Document Server Developers Guide Dec 19, 2003 27 Overview of Adobe Document Server ADS Requests 1 Product Summary
The information you need to construct command sets, and a list of file formats you can load, convert, and save are described in Chapter 3, “ADS Command Basics.” The ADS commands are described in detail in the Adobe Document Server Command Reference.
ADS Requests You invoke ADS by sending it a request. A request consists of a set of commands, one or more input files, and some other optional information. ADS provides three APIs you can use to send requests: a Java, Perl, and COM API. You can also construct your own HTTP requests and send them directly to the ADS Web service. ADS also provides a convenient command line interface for executing commands during testing and prototyping. You can specify in a request how you want ADS to return the results of its processing to you, either in a response, or by writing result files to the file system on which ADS is running. For more information on how to send requests to ADS and process the results, see Chapter 2, “Invoking ADS.” The command line interface, the Web service interface, and Java, Perl, and COM APIs are described in detail in the Adobe Document Server API Reference.
Manipulating Graphics Input ADS loads graphics files from a number of different formats, as listed in Table 1.1 on page 30. SVG files are loaded as SVG content. You can replace text and graph data in SVG content, as well as other operations. You can also convert SVG content to Raster content. All other image formats are converted internally to the PSD-like format called Raster content. You can manipulate Raster content in a variety of ways. You can: ● Change the size of an image, crop or trim it, or change its orientation. ● Add, remove, position, or flatten layers. ● Change the color mapping in the image. ● Replace the pixels in a pixel layer and the text in a text layer. You can define graphic template files that contain variables. You use ImageReady to create variables in PSD files, and Illustrator to create variables in SVG files. You can bind variables to images, text, SVG graphs and individual SVG objects, and also use them to toggle the visibility of objects or layers. You can then use ADS to replace the variable values in those templates. ADS provides a very flexible mechanism for automatic variable replacement in various circumstances. You can convert document content (PDF and PostScript®) to image content (Raster and SVG), and image content to document content (PDF and PostScript). You can save Raster content to a variety of formats, as listed in Table 1.2 on page 31.
28 Dec 19, 2003 Adobe Document Server Developers Guide Manipulating Documents Overview of Adobe Document Server Product Summary 1
For More Information ● For details on the general operations available on Raster content, see Chapter 5, “Basic Image Manipulations.” ● For details on the general operations available on SVG content, see Chapter 9, “Creating Dynamic Graphs in SVG Files” and Chapter 8, “Operations Specific to SVG Files.” ● For details on replacing text in SVG and Raster content, see Chapter 7, “Replacing Variables in SVG and PSD Files.” ● For details on variable replacement, see Chapter 7, “Replacing Variables in SVG and PSD Files.” ● For details on converting between formats, see Chapter 15, “Converting and Saving PDF Documents” and “Treating PostScript and PDF Content as Images” on page 112.
Manipulating Documents ADS accepts PDF and PostScript files and allows you to convert one format to the other. ADS provides commands that manipulate PDF documents in a variety of ways: ● You can extract information such as bookmark and link data in XML format; import, export, and merge comments; and import and export embedded data objects. For more information, see Chapter 12, “Manipulating PDF Features.” ● You can create new documents by assembling existing PDF files, and add content to documents from other PDF documents, or from form data in FDF or XFDF format. For more information, see Chapter 14, “Manipulating Pages and Documents” and Chapter 13, “Working with PDF Form Fields.” ● You can create new PDF documents from XSL Formatting Object (XSL-FO) data. You can provide formatting information either in the XSL-FO input, or via a FrameMaker template, or both. For more information, see Chapter 10, “Creating PDF Files from XSL-FO.” ● You can use ADS to encrypt and decrypt PDF documents. See Chapter 11, “Controlling Document Security.” ● If you have purchased Adobe® Document Server 6.0 for Reader Extensions, you can insert usage rights information into PDF documents that selectively enables various editing capabilities in the Adobe Reader®.
Manipulating Metadata ADS uses Extensible Metadata Platform technology (XMP) to handle metadata associated with most of the file formats it accepts. ADS can read and write metadata values in both XMP and in the EXIF and IPTC formats defined for PSD, TIFF, and JPEG. It also handles metadata in PDF files. You can export metadata from a file to examine or copy it, add, delete, or modify metadata properties for most file formats, and save files with metadata. ADS generally preserves existing metadata for those formats that do not support metadata manipulation.
Adobe Document Server Developers Guide Dec 19, 2003 29 Overview of Adobe Document Server Input, Output, and Metadata Formats 1 Format Summary
ADS adds certain metadata properties to some files that it handles, to record data such as the date the file was modified and the fact that the file was handled by ADS. For more information, see Chapter 4, “Working with File Metadata.”
Format Summary
When you load a file into ADS, it becomes ADS content. Content types do not correspond exactly to file formats; image data from most image formats is converted on load to the PSD-like Raster content type, and some content types can store more than one data format. For a complete explanation of the concept of ADS content and the relationship of content types to file formats, see Chapter 3, “ADS Command Basics.”
Input, Output, and Metadata Formats The following table summarizes the files formats that ADS can read and shows the content type in which each format is loaded.
TABLE 1.1 Input file formats allowed by ADS
Content File format type Typical usage
PSD Raster Raster image data to be manipulated with the graphics commands. TIFF GIF JPEG PNG
SVG SVG Vector image data to be manipulated with the graphics commands.
PDF PDF Document input to be transformed to an image format or manipulated with the document commands.
PostScript PostScript Document input to be transformed to an image or PDF format. EPS
XML XML Replacement data for SVG or PSD variables, or other miscellaneous uses.
XMP XMP Replacement metadata values to be added to appropriate types of content, or extracted metadata being retrieved.
FDF FormData New or replacement form data or comments to import into existing XFDF PDF content.
XSL-FO XSL-FO Content to be transformed to PDF.
FM Frame Formatting template for XSL-FO content being transformed to PDF. MIF
30 Dec 19, 2003 Adobe Document Server Developers Guide Input, Output, and Metadata Formats Overview of Adobe Document Server Format Summary 1
The list below shows which TIFF variants ADS can read (load) and write (save):
Byte order Intel bye order (PC order in Photoshop) read & write Motorola byte order (Mac order in Photoshop) read Grayscale, RGB, CMYK (standard ink order only, 8–bit and 16–bit read & write Color modes chunky color) Compression LZW read
When saving content that was loaded in TIFF format, ADS preserves the following information from the original input:
Clipping Paths When saved to EPS, TIFF, PSD, and PDF formats Resolution When saved to EPS, TIFF, and PSD formats Metadata EXIF, IPTC, and XMP
FDF (Forms Data Format) is a file format based on PDF that is used to express interactive form data and annotations in PDF files. This format allows you to export form and annotation data from a PDF file, store it in another file, and import the data into another copy of the same PDF document. For more information on FDF, see Chapter 8 in the PDF Reference, fourth edition. XFDF is an XML version of FDF. This format is described in the Adobe technical note XML Forms Data Format Specification, Version 2.0. FM is the native binary FrameMaker file format. MIF (Maker Interchange Format) is a pure text form of a FrameMaker file. You can use MIF format to access FrameMaker files from other applications. The following table shows the content types ADS provides and the file formats which you can save from each content type.
TABLE 1.2 Output file formats produced by ADS
Content type File format
Raster PSD, TIFF, GIF, JPEG, PNG8/24, WBMP
SVG SVG
PDF PDF, Web-optimized PDF ADS can also write out embedded data objects from PDF files byte-for-byte, regardless of format.
PostScript PostScript, encapsulated PostScript (EPS), Photoshop EPS
XML XML
XMP XMP
FormData FDF, XFDF
Adobe Document Server Developers Guide Dec 19, 2003 31 Overview of Adobe Document Server Format Conversions 1 Format Summary
The following table shows the metadata formats that ADS preserves and supports, and shows which file formats and content types can contains which metadata formats:
TABLE 1.3 Metadata formats supported and preserved by ADS
Metadata formats supported File formats Content type
EXIF, IPTC PSD, TIFF, JPEG Raster
XMP PSD, TIFF, JPEG, GIF, PNG Raster
SVG SVG
PDF PDF
Photoshop EPS PostScript
XSL-FO XSL
For files containing metadata in EXIF or IPTC formats, those values are preserved in XMP format when the file is loaded. When you save Raster content to a PSD or TIFF file, ADS writes the metadata in all three formats. When you save Raster content to a JPEG file, ADS can write metadata in none, any, or all of the formats. For Raster, SVG, and PDF content, you can directly manipulate metadata only in XMP format. You can change, delete, or add properties. You can also export or import XMP metadata to or from an XMP file. For XSL content and Photoshop EPS, existing XMP metadata is preserved but you cannot manipulate it. Metadata is not preserved for other kinds of PostScript content.
Format Conversions Some file formats are transformed on load (see Table 1.1) and some content types can be transformed on save (see Table 1.2). In addition, you can perform some explicit content type conversions on loaded content, as listed in Table 1.4.
TABLE 1.4 Direct content type conversions supported by ADS
Raster ➟ EPS ➟ PDF SVG ➟ Raster ➟ PDF PDF ➟ Raster ➟ EPS
PostScript ➟ Raster EPS ➟ PDF
32 Dec 19, 2003 Adobe Document Server Developers Guide Format Conversions Overview of Adobe Document Server Web-Related Standards and Formats 1
You can combine any number of these conversions. For example, you can load a JPEG file, which is loaded as Raster content, convert the Raster to PDF, and save out a PDF file. You can load an SVG file, convert it to Raster, convert it again to EPS, and save out an EPS file.
Web-Related Standards and Formats
ADS takes advantage of many Web-related standards. The command set is defined in XML, and you use XPath syntax to identify parts of Raster and SVG files. You use URIs (Uniform Resource Identifiers) to identify source files, and locations for result and log files. You can load XML data and use it to replace various kinds of data in the files you are processing. ADS also makes use of various Web-related formats such as SOAP, PDF, SVG, XMP, and XSL-FO. For an overview and a description of how these formats and protocols are supported and used in ADS, as well as information on formats and extensions that ADS defines or uses, see the Adobe Document Server XML Grammars Reference. Many of these standards and formats are defined by the Internet Engineering Task Force (IETF) or the World Wide Web Consortium (W3C). ● For more information about SVG, SOAP, and other W3C standards, see the W3C site (www.w3.org). ● For more documentation of Adobe formats and protocols and Adobe extensions to standard formats and protocols, such as PDF, see the Adobe Web site (www.adobe.com). ● URIs are defined by IETF specifications.
Adobe Document Server Developers Guide Dec 19, 2003 33 Overview of Adobe Document Server Format Conversions 1 Web-Related Standards and Formats
34 Dec 19, 2003 Adobe Document Server Developers Guide 2 Invoking ADS
This chapter contains a summary of the architecture of ADS and the various ways you can send it requests, and explains the underlying model of an ADS request and response. For more detailed information about these topics, see the Adobe Document Server API Reference. This chapter also provides a complete description of how you specify file locations using URIs in the API methods, on the command line, and in command attributes. This chapter contains the following sections:
Deploying and Invoking ADS starting on page 35 The Interface Model starting on page 37 Details of the Objects in the Model starting on page 39 How ADS Handles URIs starting on page 43
Deploying and Invoking ADS
You can deploy ADS as a library and as a Web service. Once deployed, you have a choice of invocation mechanisms: the command line, one of three APIs (Java, Perl, or COM), or a direct connection to a Web service. Table 2.1 summarizes how the deployment and invocation choices are related.
TABLE 2.1 Deployment and invocation choices for ADS
Possible invocation choices Deployment choice Java API Perl API COM API Other Command line
Library ✔✔✔ ✔
Web service ✔✔ ✔
When you install ADS as a library, you can access it locally from the command line or the Java, Perl, or COM APIs. Depending on how you configure your systems, it is possible to access ADS as a library remotely from COM. When you install ADS as a Web service, you can access it from another system using the Java or Perl APIs, or directly by constructing your own HTTP request. Of course, local access to the Web service is also allowed. Figure 2.1 shows the same information as the table above. In addition, it shows where individual processes or process pools can be used.
Adobe Document Server Developers Guide Dec 19, 2003 35 Invoking ADS 2 Deploying and Invoking ADS
FIGURE 2.1 Deployment and invocation choices for ADS
Remote system Local system ADS Web Service
Other code Web service process pool
Perl API local process
Java API local process
remote process local process pool remote process pool
COM API local process local process pool
Command Line local process
Which interface you choose to use to invoke ADS depends on the larger environment in which you are deploying ADS, and which language or mechanism you want to use to access ADS functionality. Table 2.2 lists the four interfaces and the circumstances under which you might choose to use each one.
TABLE 2.2 Details of invocation choices for invoking ADS
Interface Access modes Usage scenarios
Command line Local execution In an environment that supports command line Windows & Solaris™ mode, for simple invocation of ADS. You can work interactively directly on the command line, or from scripts that you can run from the command line or through some automatic mechanism such as cron.
Java API Local and remote execution In any situation where you can write Java code to Windows and Solaris invoke ADS, for example, in Java applications or servlets, or in JSP pages.
Perl API Local and remote execution In any situation where you can execute Perl scripts, Windows and Solaris for example, CGI scripts.
COM API Local and remote execution In any situation where you can execute code in any Windows only language with COM support, such as JavaScript, VBScript, Visual Basic, .NET, VBNET, Perl, Java, C, C++, and C#.
Web service Remote execution From any Web–service–enabled client.
When writing a set of commands, it is important to know how the commands will be submitted for processing. For example, the ways in which a command can refer to an input file
36 Dec 19, 2003 Adobe Document Server Developers Guide The Objects in the Model Invoking ADS The Interface Model 2
or specify an output file location depend upon whether the request was made on the command line, an API, or directly to the Web service, and further on what data and information was included with the request. There are also some interactions between specifications made on the command line or in a request, and those made within a set of commands. For example, you can specify a result location (where result files are written) on the command line, in the commands themselves, or both, or you can write results into a results object to be sent back to the client.
The Interface Model
While they differ in some respects, the invocation mechanisms are all based on a common model and rely on the same core ADS code that executes requests. This model defines objects that represent a server, request, response, and result. The three APIs implement this model directly, creating objects in their respective languages. The XML syntax for expressing ADS requests in an HTTP request is also based on the same object relationships. The command line interface more loosely matches the model.
The Objects in the Model Table 2.3 explains briefly what each of these conceptual objects represents, and the following sections provide a more detailed description of the objects.
TABLE 2.3 The object model of the ADS interfaces
Object Represents
Server An ADS process or service that executes a request and returns a response.
Request A collection of all the necessary commands, input data, and request–specific settings needed to send a request to ADS.
Result A unit of output from an executed command. The form of the output may be result content (current content when the command finishes), a result file (written to the local file system), or a named result that can be collected into a response object. You may get one or more output results from executing a request.
Response A collection of log messages and results produced by an ADS server during the execution of a request, to be returned to the client. A response can contain zero or more results.
Interacting with ADS In general, an interaction with ADS involves a number of steps. These steps vary depending on the interface you use to invoke ADS, as outlined in the following table. This table distinguishes
Adobe Document Server Developers Guide Dec 19, 2003 37 Invoking ADS Interacting with ADS 2 The Interface Model
between calling ADS from the command line, from one of the 3 APIs (Java, Perl, COM), or by sending an HTTP request directly to the ADS Web service (without using the Java or Perl API).
TABLE 2.4 Steps involved in interacting with ADS
Step Interface Details Creating an ADS Java, Perl, COM APIs The Java and Perl APIs provide constructors for server objects. Server object Object construction is an integral part of COM. Web service direct N/A Command Line N/A Creating an ADS Java, Perl, COM APIs Java and Perl APIs provide request object constructors. Object Request object construction is an integral part of COM. All three APIs provide methods for populating the request object with the required information. Web service direct The HTTP message sent to the Web service is the request. Command Line You can loosely view the information passed in the command line options as the request. Sending a request to a Java, Perl, COM APIs All 3 APIs provide an execute method in the server object’s server class that sends a request to a server. Web service direct Sending an HTTP message to the Web service constitutes sending a request. Command Line Invoking ADS on the command line “sends” the “request.” Receiving a response Java, Perl, COM APIs The execute method returns a response object. Log messages from the server are always included in the response object, but may also be (A response consists written to a log file on the server’s file system. Result content is of log messages and returned either in the response object or written to the server’s result content.) local file system. Web service direct The Web service returns a response to the request message. The response contains log messages. Settings in the commands determine whether results are included in the response message or written to the Web service’s file system. Command Line Log messages are sent to the standard error stream. Result files are written to the local file system.
38 Dec 19, 2003 Adobe Document Server Developers Guide Server Objects in the APIs Invoking ADS Details of the Objects in the Model 2
TABLE 2.4 Steps involved in interacting with ADS
Step Interface Details Processing the contents Java, Perl, COM APIs Methods are provided for extracting the log messages and of a response results from the response object. If the results were written to the file system, you can inspect them with appropriate applications. Web service direct You can use any method you choose to extract log message and result information from the HTTP response. If results were written to the file system, you can inspect them with appropriate applications. Command Line You can redirect the standard error stream to a file for further examination of log messages. You can inspect result files with appropriate applications. Releasing a server Java, Perl, COM APIs With library deployment, Server objects persist until you when you are finished explicitly release them, which releases their association with with it any ADS process and makes them available for garbage collection. (N/A for Web service deployment). Web service direct N/A Command Line N/A
Details of the Objects in the Model
The information in this section is a high level presentation of the details of the server, request, response, and result objects as given in the Adobe Document Server API Reference. An overview is provided here so that you can understand the context in which commands are executed.
Server Objects in the APIs When you create a server object in any of the APIs, that object is associated, directly or indirectly, with an ADS process. Whether this association persists for the course of a single request or for the life of the object depends on what kind of Server object it is. Table 2.5 shows the several kinds of server objects and how they are associated with ADS processes.
Adobe Document Server Developers Guide Dec 19, 2003 39 Invoking ADS Requests 2 Details of the Objects in the Model
TABLE 2.5 Kinds of server objects in the APIs
Direct server object Associated with a single ADS process on the same system on which the server object is created, for the lifetime of the object.
Pooled server object Associated with a pool of ADS processes on the same system on which the server object is created. Each time you send the object a request, a different process from the pool can execute the request. Web service server object Associated with an ADS Web service, which uses a pool of ADS servers to execute requests it receives. The ADS Web service may exist on either the local system or a remote one. Each time you send the object a request, a different process from the pool can execute the request. You can establish a regular connection or a secure connection to the Web service when you create this type of object.
COM server objects Associated with a single or pooled ADS process. Pooling is an inherent part of COM+, so you can create either single processes or process pools. Whether or not the process or pool is local or remote from the system on which the server object is created depends entirely on how your system or systems were configured during installation.
When you send a request to a server object that will execute remotely, there are some concerns you must consider, such as whether to include your input files in your request and whether to ask ADS to return your results in the response object or write them to the remote file system; these decisions can affect the speed at which the request is processed, due to increased transmission time. These concerns are discussed in detail in the Adobe Document Server API Reference.
Requests When you invoke ADS, you must provide all the information it needs in order to do what you want it to do to your input files. This information includes specifying the input data on which you want ADS to operate, a set of operations to perform, and how to save the results of those operations. In addition, you can control certain aspects of how ADS behaves while processing this information. The collection of all necessary commands, input data, and settings needed for a single invocation of ADS is called a request. The actual form the request takes depends on which interface you use to invoke ADS: ● If you invoke ADS from the command line, your request specified by the command line options and the contents of the command file you provide (if any—ADS can perform certain default operations on a file passed in on the command line when you do not specify a command file). ● If you invoke ADS from the Java, Perl, or COM API, you construct a request object provided by those APIs and put the appropriate information into it.
40 Dec 19, 2003 Adobe Document Server Developers Guide Results and Responses Invoking ADS Details of the Objects in the Model 2
● If you invoke the Web service directly, you construct an appropriate HTTP request based on the WSDL (Web Services Description Language) for the Web service, using tools of your choice. In general, the following pieces of information are part of an ADS request:
TABLE 2.6 The kinds of information in an ADS request
Information Details
Input data File content of any file type allowed by ADS.
ADS commands A set of commands for ADS to execute on the input data.
Variable substitution data Replacement values for variables defined in PSD and SVG files.
User–defined variables Values for user-defined variables that can be referenced within commands. Available only from the command line interface.
Settings for ADS behavior Values for certain parameters that control how ADS behaves while processing the request, including a base URI for the result location, whether result files should be overwritten, and the error behavior. These values can also be specified in the commands. If a value is specified both in the request and in the commands, the value set in the request takes precedence.
For details of how to construct requests for all of the invocation interfaces, see the Adobe Document Server API Reference.
Results and Responses When you invoke ADS from one of the APIs or directly via the Web service, you can specify a result location in which ADS writes result files; this location must be locally accessible to the ADS process that executes the request. If you don’t specify a result location, or otherwise save your results to the file system, result content is returned to you in a response. When you invoke ADS from the command line, all result files are written to the local file system. Whenever you make a request from one of the APIs, ADS returns a response object. Response objects contain a (possibly empty) collection of log messages and a (possibly empty) collection of results. Log messages are simple strings, but results are represented by yet another object, the result. A result object contains the file data for the result. It also contains information about that data, such as the name it was given in the commands when it was saved, an appropriate file extension, its MIME type, and if it is image data, the height and width of the image in pixels.
Adobe Document Server Developers Guide Dec 19, 2003 41 Invoking ADS Logging 2 Details of the Objects in the Model
Logging While an ADS process executes a request, it may output log information of various kinds. You can control the types of messages ADS logs and where it writes the log information. Log Levels Each log message starts with a prefix that corresponds to the level number. Levels (0-7) group messages according to their severity and importance in the system, as shown in Table 2.7. You can set a parameter that causes ADS to report messages only at or below a particular level, using a command-line option or the appropriate API method when constructing a request.
TABLE 2.7 Log levels and their meaning
Level Prefix Use in ADS
0 [FATAL] Not currently used.
1 [ALERT] Not currently used.
2 [CRITICAL] ADS has failed to complete the current request. No further commands will be executed for this request.
3 [ERROR] An error occurred that makes it impossible for ADS to execute the current command. If the ADS process executing this request is configured to stop on errors, a log message at this level will be followed by a critical (level 2) message saying the request cannot be processed.
4 [WARNING] A possibly incorrect but recoverable situation has occurred during the execution of a request. This is the default log level.
5 [NOTICE] A significant event of interest occurred during execution.
6 [INFO] A common but interesting event occurred during execution.
7 [DEBUG] Not used.
Log Message Destinations Where log messages are written varies across the invocation mechanisms: ● The command line sends all log messages to the standard error stream. ● The APIs allow you to specify a log destination for single server objects and for server pools. Regardless of whether or not you specify a log location, ADS always includes the log messages generated by your request in the response object. The APIs also provide a way to retrieve log messages for a request if ADS fails to finish executing it and does not return a response object. ● Log file location is configured by an administrator when the Web service is installed. For details of the command-line options and API methods related to logging, see the Adobe Document Server API Reference.
42 Dec 19, 2003 Adobe Document Server Developers Guide Logging Invoking ADS How ADS Handles URIs 2
How ADS Handles URIs
There are many places in the ADS interfaces and the ADS command language where you must supply a URI for the value of a parameter or attribute. This section explains the basic concepts you need to know in order to understand when absolute URIs are required, and how relative URIs are resolved. This explanation assumes the following definitions:
Absolute URI A URI that begins with a scheme name, such as file:///C:/myfiles/working Relative URI A URI that does not begin with a scheme name. Relative URIs can be absolute or relative paths, or simple names with no path information in them. The following are all relative URIs: /tmp/logfiles, ../myfiles/working, myfiles/working, image.psd Absolute path (Solaris) A path that begins with a forward slash, such as /tmp (Windows) A path in one of three forms: • A path that begins with a drive name, such as C:/myfiles/working/image.psd • A UNC path that starts with // • A UNC path that starts with \\
NOTE: ADS transforms \\ to // on Windows. Absolute paths are relative URIs. Relative path (Solaris) A path that does not begin with a forward slash, or a simple name with no slashes or colons in it. (Windows) A path that does not begin with a drive name or with double slashes, as explained in the row above (Absolute path), or a simple name with no slashes or colons in it. Relative paths are relative URIs. Base input URI An absolute URI used to resolve relative URIs for arguments that specify input data for ADS. The three APIs, the command line, and the core ADS process that executes requests all have their own base input URI. Base output URI An absolute URI used to resolve relative URIs for arguments that specify output data for ADS. The command line and the core ADS process that executes requests all have their own base output URI. (The SDK executables do not have base output URIs.)
Adobe Document Server Developers Guide Dec 19, 2003 43 Invoking ADS Base URIs for the APIs 2 How ADS Handles URIs
ADS supports the following schemes for URIs:
TABLE 2.8 Supported URI schemes
file: Supported in all APIs and the commands
http: Supported only when specifying the URL of an ADS Web service. (Java and Perl APIs)
https: Supported only when specifying the URL of an ADS Web service. (Java API only)
adobe-content: Supported in some of the commands for specific purposes.
Base URIs for the APIs Some of the methods in the Java, Perl, and COM APIs have parameters that take URIs. In some cases, you can specify relative URIs; in many cases you must provide absolute URIs. Base Input URI: The SDKs establish their own base input URI, which is the current working directory in which the SDK was executed. Since you may or may not know what this location is, absolute URIs are usually recommended. The base input URI uses the file: scheme. You can always specify an absolute URI; in this case, the base input URI is ignored. Base Output URI: The SDKs do not have a base output URI, so you must provide absolute URIs for all method parameters that identify output locations. See the Adobe Document Server API Reference for method details. The entries for each of the method parameters in the APIs specify whether or not a relative URI is allowed.
Base URIs for the Command Line Base Input and Output URIs: The command line establishes base input and output URIs, both of which are the current working directory, the directory in which you invoked the command line. Both base URIs use the file: scheme. Any relative URIs you specify as argument values on the command line are resolved against the appropriate base URI. If you supply any absolute URIs as argument values on the command line, they must use the file: scheme. When you specify an absolute URI, the base URI is ignored. All URIs you specify for the command line must identify files on the local file system. See the Adobe Document Server API Reference for argument details. The entries for each of the command line arguments in that document specify whether or not a relative URI is allowed.
44 Dec 19, 2003 Adobe Document Server Developers Guide Base URIs for an ADS Process Invoking ADS How ADS Handles URIs 2
Base URIs for an ADS Process Establishing the base URIs for an ADS process is more complicated than for the SDKs or the command line. The base input URI is influenced by which interface you use to submit the request and where the commands are for the request. The base output URI is influenced by which interface you use to submit the request and whether or not a result location is specified for the request. (You can specify a result location on the command line, in an API Request object, or in the commands themselves.) The base URIs for an ADS process set the context for all relative URIs used in ADS commands. API Invocation Base Input URI: When you construct a Request object in any of the APIs, you can either include the commands themselves in the Request object, or you can specify a command file on the file system, which ADS reads to obtain the commands. If you include the commands in the Request object, the base input URI is the Request object. All relative URIs for input attributes in commands, such as the loadContent command, must be either simple names with no path information in them (no slashes or colons) or absolute file: URIs of files on the system local to the ADS process. If you specify a command file on the file system, the base input URI is the location of that command file, using the file: scheme. In this case, relative URIs for input attributes in commands, such as the loadContent command, can be simple file names or can contain path information (slashes or colons), and are resolved against the base input URI. Base Output URI: When you construct a Request object in any of the APIs, you can specify a result location to which result files are written. The commands for the request can also specify a result location. (If it is specified in both places, the request setting takes precedence). The result location must be a directory locally visible to the ADS process that executes the request. If you do not specify a result location, the base output URI is the Response object that is returned. All relative URIs for output attributes in commands, such as the saveContent and saveOptimized commands, must be either simple names with no path information in them (no slashes or colons) or absolute file: URIs of files that are written to the file system local to the ADS process. If you specify a result location, the base output URI becomes the location specified. The result location must be specified using the file: scheme. All relative URIs given for output attributes in commands, such as the saveContent and saveOptimized commands, are resolved against this base output URI. Regardless of what the base input or output URIs are, you can always specify an absolute URI, using the file: scheme, in which case the base URI is ignored. Command Line Invocation Base Input URI: When you submit a request to ADS from the command line, the base input URI is the location of the command file, if you specify one; otherwise, it is the current working directory. All relative URIs for input attributes in commands, such as the loadContent command, are resolved against this base input URI.
Adobe Document Server Developers Guide Dec 19, 2003 45 Invoking ADS Base URI Summary 2 How ADS Handles URIs
Base Output URI: When you submit a request to ADS from the command line, the base output URI is the result location if you specify one; otherwise it is the current working directory. All relative URIs for output attributes in commands, such as the saveContent and saveOptimized commands, are resolved against this base output URI. Both base URIs use the file: scheme. Regardless of what the base input or output URIs are, you can always specify an absolute URI, using the file: scheme, in which case the base URI is ignored. See the Adobe Document Server Command Reference for details on which commands have attributes that require URIs. The entries for each of these attributes specify whether or not a relative URI is allowed.
Base URI Summary The following table summarizes the base URIs for the APIs (SDKs), the command line, and the core ADS processes (the context of the commands). All base URIs that are not the Request or Response objects use the file: scheme.
TABLE 2.9 Base URIs for the ADS interfaces
Interface where URIs occur Condition Base URI Java, Perl, COM APIs Input: Location where SDK was (Method calls) executed Output: N/A Command line Input: Current working directorya (command line arguments) Output: Current working directory ADS process Invoked from Commands in Request object Input: Request object (command attribute APIs Commands in file on ADS Location of command file values) server’s file system Result location not set Output: Response object Result location is set Result location Invoked from Command file supplied Input: Location of command file command Command file not supplied Current working directory line Result location set Output: Result location Result location not set Current working directory
a. The directory in which the command line is invoked.
46 Dec 19, 2003 Adobe Document Server Developers Guide 3 ADS Command Basics
This chapter describes fundamental information you need to understand about how some of the basic ADS commands work and how to optimally combine commands in a command set. It explains how to specify and load input content, how ADS handles that content during request execution, and how to save output content. It describes the file formats, content types, conversions, and transformations that ADS supports. It also describes the techniques and mechanisms for specifying and working with content in commands, including how to handle metadata in the input data, and the ways in which you can specify attribute values for the ADS commands. This chapter contains the following sections:
Overview starting on page 47 Content Holders and Types starting on page 48 Loading Content starting on page 53 Converting Content starting on page 57 Saving Content starting on page 59 Referenced Attributes Values starting on page 65 General Commands starting on page 66
Overview
Chapter 2 explained the various parts of an ADS request, one of which was a set of commands that direct ADS to perform a series of operations on specified input. You can specify this command sequence in various forms (stream, string, filename, or URI) depending on which interface you use to invoke ADS; the general term command set applies to all of these forms. The ADS commands are defined using an XML syntax. A command is an element, and its parameters are its attributes. A command set contains a sequence of ADS commands in a command element. Observe the following conventions when writing command sets: ● The command set is an XML construct, and must conform to WC3 standards for well-formed XML documents. ● Indicate the text encoding in the first line of the command set. The text encoding controls how ADS processes data it reads from the command file and from input files. The UTF-8 text encoding is fully supported, and recommended.
Adobe Document Server Developers Guide Dec 19, 2003 47 ADS Command Basics 3 Content Holders and Types
NOTE: UTF-16 and Shift-JIS encodings may work in certain situations, but may cause errors in others. Use these encodings with caution. ● ADS commands are case sensitive. ● Comments can be included in a command set. The format for comments is: Two hyphens at the beginning and end delineate the comment. It is a syntax error to use two or more hyphens within the body of the comment. Generally, a command set contains one or more loadContent commands, other commands that manipulate the loaded content in some way, and one or more save commands that save the results. When you load an input file, ADS determines the type of the file’s contents and reads the file data into an appropriate content holder. ADS provides a number of different content holder types to hold the various file formats allowed as input. Once a file is loaded, it is called ADS content. Once you have loaded your input data, you can explicitly convert some content types to other content types, and perform other supported operations on the content. When you save content, ADS outputs the content in one of its supported output file formats, depending on the type of content being saved. The act of saving content to one of the supported file formats may transform the content again, depending on a number of factors, such as the original input format, optimization settings in the content itself, and which save command you use to save it.
Content Holders and Types
When you load an input file, the content of the file being loaded is stored in a content holder. A content holder is temporary storage that ADS uses while it processes a request. This section explains that mechanism. Almost all ADS commands create a new content holder to contain the result of the operation. Every content holder is of a particular type, which reflects the file type of the contents that go in it. The type of a content holder is determined by the command that creates it. See “Content Types and File Formats” on page 51. At any given time, there is one and only one current content holder. All other content holders are, by default, not current. You can think of the current status as a single label that moves around from content holder to content holder as command execution progresses. The next section explains this in more detail. You can name a content holder with the out attribute of a command, so that you can access it in subsequent commands. (The ADS documentation generally refers to a named content holder simply as “named content.”) Most of the commands have one or more input attributes that take content holder names as values. If you do not name a content holder, you can only access it as
48 Dec 19, 2003 Adobe Document Server Developers Guide How Content Becomes Current ADS Command Basics Content Holders and Types 3
long as it is current. When another content holder becomes current, the unnamed content holder is no longer accessible.
TIP: Try to order your commands to minimize the number of load operations for which you must name the resulting content. Doing this minimizes the amount of memory used during processing.
How Content Becomes Current Content becomes current in two ways: ● The content holder created by a command to hold the result of that command becomes current when the command terminates. This is true whether or not you name the content with the out attribute. ● If you specify the in attribute for a command, the named content that you specify becomes current before the command performs its operation. A command always operates on the current content. If you do not specify the in attribute for a command, it operates on the result of the previous command, regardless of whether that result was named. You can reuse the same content names in multiple commands. When you assign a name to a new content holder, the content holder that previously had that name is discarded and becomes inaccessible. If you use the same content name for both the in and out attributes of a command, the name is assigned to the result of the operation, and the content that was input to the command becomes inaccessible. The save commands (saveContent and saveOptimized) write the current content to two places: ● Into a new content holder — This new content becomes current when the save command terminates, and the content is not transformed. You can optionally name the new content with the out attribute. ● Into a named file — The act of writing the current content to a file of a specific format may optimize the contents, if the content being saved is able to be optimized and optimization settings in the content are appropriately set.
Adobe Document Server Developers Guide Dec 19, 2003 49 ADS Command Basics How Content Holders Work 3 Content Holders and Types
How Content Holders Work The following command sequence illustrates the changing state of content holders during execution, and is designed to illustrate all the important points about how content holders work. Each line in the sequence is numbered; the number corresponds to the explanation below of what happens when that line is executed, with an illustration of the content holder situation at that point. These commands load two PSD files and perform various rotation operations on them, saving them out to result files at the end. 1
1.
The load command creates a content holder named image1 image1 into which it puts the contents of the input file arrow.psd. This becomes the current content holder when the command completes. current
2.
The load command creates a new unnamed content holder image1 into which it puts the contents of the input file square.psd. This becomes the current content holder when the command completes. current
3.
The rotate command operates on the current content. It image1 image2turned creates another content holder named image2turned to hold the result of the rotate operation. This becomes the current content holder when the command completes. Note that at this point, the content loaded in the second current command is no longer accessible because that content holder was not named and is no longer current. 4.
The rotate command rotates the current content and puts image1 image2turned the result in another, unnamed content holder. The new unnamed content becomes the current content when the command completes. current
50 Dec 19, 2003 Adobe Document Server Developers Guide Content Types and File Formats ADS Command Basics Content Holders and Types 3
5.
This command resets the current content to a previously image1 image2turned saved content holder, image1, (from the first load) before it performs its operation. Note that at this point, the content produced by the fourth command is no longer accessible because the content current holder it is in was not named and is no longer current.
The command then rotates the current content, image1, image1 image2turned image1turned 180 degrees and saves it in a new content holder, called image1turned, which becomes the current content.
current
6.
This command creates a result file called pic1.psd from image1 image2turned image1turned the current content. When the command ends, image1turned is still the current content. current
7.
This command resets the current content to the named image1 image2turned image1turned content image2turned. It then creates a result file called pic2.psd from the current content. When the command ends, image2turned is still the current current content.
Content Types and File Formats Table 3.1 lists all the allowed input file formats. For each input format, it shows what content type that type of input becomes, and what formats you could save that content in, if you did not convert it to some other form before saving it or otherwise mark it to be saved in a different format. Notice that you can save all types of content with the saveContent command, but only some types with the saveOptimized command. For image content types, the saveOptimized command determines the output format from optimization settings in the content itself. If the content does not specify optimization settings, the content is saved as GIF. For PDF content, the saveOptimized command saves it to PDF 1.5 format optimized for Web use.
Adobe Document Server Developers Guide Dec 19, 2003 51 ADS Command Basics Content Types and File Formats 3 Content Holders and Types
TABLE 3.1 How content types relate to input and output formats
Input file Content format type Save command Output file format
PSD Raster saveContent PSD saveOptimized GIF, JPEG, PNG8, PNG24, WBMP
GIF Raster saveContent PSD saveOptimized GIF, JPEG, PNG8, PNG24, WBMP
JPEG Raster saveContent PSD saveOptimized GIF, JPEG, PNG8, PNG24, WBMP
PNG Raster saveContent PSD saveOptimized GIF, JPEG, PNG8, PNG24, WBMP
TIFF Raster saveContent TIFF saveOptimized GIF, JPEG, PNG8, PNG24, WBMP
SVG SVG saveContent SVG saveOptimized GIF
PDF PDF saveContent PDF saveOptimized Web-optimized PDF
PostScript PostScript saveContent PostScript
EPS PostScript saveContent EPS
Photoshop EPS PostScript saveContent Photoshop EPS
XML XML saveContent XML
XMP XMP saveContent XMP
FDF FormData saveContent FDF
XFDF FormData saveContent XFDF
XSL-FO XSL saveContent XSL-FO
FM Frame saveContent FM
MIF Frame saveContent MIF
52 Dec 19, 2003 Adobe Document Server Developers Guide Specifying Input Data ADS Command Basics Loading Content 3
Loading Content
You must load all your input data into content holders before the ADS commands can access it. This section explains how you specify input data for a request, and how you load that data with the loadContent command in a command set. It also describes the details of how input file content may be transformed when it is loaded into content holders.
TIP: For best performance, minimize the number of input files in a request. For example, if you have six PSD files that you want to process in the same way, it is more efficient to send six requests, each with a short command set that loads and saves one file, than to send one request with a command set that loads and saves six files.
Specifying Input Data If you send ADS a request using the Java, Perl, or COM API, you can include one or more input files with the request using the addFile method. You must explicitly load this input in your command set, using the name either you or ADS gave the input data. When you execute a request from the command line, you must also load input data explicitly, unless you are processing only one file and you specify that file on the command line. Loading Input Data Explicitly You use the loadContent command to explicitly load data into a content holder. If you submit a request with one of the APIs, the first command in your command set must be a loadContent command. If you submit a request from the command line, the first command in your command set must be a loadContent command unless you specify the -source argument on the command line. The value of the source attribute is a file URI. The file it identifies must be locally accessible to the ADS process on the file system where it is running. ● If you invoke ADS from the command line, or you specify a command file on the server from one of the APIs (you use the setCommandsFileOnServer method on the Request object), relative URIs for the source attribute are resolved with respect to the location of the command file. You can always specify an absolute URI. ● If you invoke ADS from one of the APIs and include the commands in the Request object, the value you provide for the source attribute must be either an absolute file URI or the name associated with the content when the file was added to the request with the addFile command. These names cannot contain slashes or colons. A simple name directs ADS to get the input data from the Request object; an absolute URI directs it to the local file system.
Adobe Document Server Developers Guide Dec 19, 2003 53 ADS Command Basics Specifying Input Data 3 Loading Content
TABLE 3.2 Specifying input data sources in the loadContent command
Form of source attribute Details Allowed Absolute file URI: Identifies a file on the local file Always. file:///mydir/myfile.ext system of the ADS process. (Solaris) Base input URI is ignored. file:///C:/mydir/myfile.ext (Windows) Absolute path: Identifies a file on the local file Allowed in all circumstances in /mydir/myfile.ext system of the ADS process. which the command file exists on C:\mydir\myfile.ext Considered a relative URI, and the local file system. resolved against the base input This condition is always true when URI. In this case, only the scheme invoking ADS from the command part of the base URI is needed to line, and from the APIs when resolve the URI. specifying the command file for the request with the Relative path: Identifies a file on the local file setCommandsFileOnServer system of the ADS process. mydir/myfile.ext method. myfile.ext Considered a relative URI, and This condition is not true when resolved against the base input myfile invoking ADS from an API and URI. including the command set in the Allowed only when the command request object (by using a setFile* file resides on the local file system. command that doesn’t end with “OnServer”). name Identifies input data in the request Required when invoking ADS from object. In this case, the name must one of the APIs and referencing not contain slashes or colons input data added to the request with (‘\’, ‘/’, or ‘:’). the addFile method. The base input URI is the request If the request contains any input object. data added in this way, the only forms you can use for the source attribute are this one and an absolute URI.
Loading Input Data Automatically Automatic loading occurs only when you invoke ADS from the command line. For files that you specify in command-line arguments, you can use either a relative or absolute path. In this case, relative paths are interpreted with respect to the current working directory. ● You can specify one input file on the command line with the -source argument. If you do this, ADS automatically loads that file into a content holder of the appropriate type named srcfile, before executing any commands in your command file. ● You can add variable replacement data on the command line, with the -data argument. If you do this, ADS automatically loads the replacement data into an XML content holder named data.
54 Dec 19, 2003 Adobe Document Server Developers Guide How File Formats Map to Content Types Upon Load ADS Command Basics Loading Content 3
If you specify either or both of these arguments, you can still load other input data with explicit loadContent commands in your command file, and can reference the automatically loaded content by name in any command. You can also specify user-defined variables and values on the command line. All variables and values are collected into an XML content holder named commandLineArguments. For details of the command-line arguments, see the Adobe Document Server API Reference.
How File Formats Map to Content Types Upon Load Table 3.3 shows all the input file formats ADS can handle, and the type of content holder into which each format is read. The next section, “Converting Content” on page 57, explains how you can transform loaded content to other content types. ADS uses an internal, PSD-like format to store and operate on all raster image data. All raster-based file data is transformed to this format when loaded. The transformed image data is called Raster content. When Raster content is loaded, it is marked to be saved in a particular format. The section “The Format Flag on Raster Content” on page 62 explains how you can change this setting. In most cases, when you load an image file from PSD, TIFF, JPEG, or Photoshop EPS format that was produced by Photoshop, ADS reads Photoshop Image Resources such as clipping paths and color profiles and updates them as necessary. For more information on color handling for image formats, see “Color Space Support in ADS” on page 102.
TABLE 3.3 Loading file data with the loadContent command
Content File format type Description Typical uses PSD Raster ADS automatically transforms the file contents to the Image data to be internal Raster format, maintaining all layers and layer manipulated with the names. If the PSD file has a background layer, it is graphics commands. always the first layer, layer[1] or layer[first()]. Any optimization settings that were present in the file are preserved. The content is marked to be saved in PSD format by the saveContent command. GIF Raster ADS automatically transforms the content to the Image data to be JPEG internal Raster format with one unnamed layer, manipulated with the PNG layer[1]. The content contains no initial graphics commands. optimization settings. The content is marked to be saved in PSD format by the saveContent command.
Adobe Document Server Developers Guide Dec 19, 2003 55 ADS Command Basics How File Formats Map to Content Types Upon Load 3 Loading Content
TABLE 3.3 Loading file data with the loadContent command (Continued)
Content File format type Description Typical uses TIFF Raster ADS automatically transforms the content to the Image data to be internal Raster format with one unnamed layer manipulated with the layer[1]. The content contains no initial graphics commands. optimization settings. The content is marked to be saved in TIFF format by the saveContent command. If you subsequently add PSD features, such as new layers, to this content, and want to preserve them, you must explicitly mark the content to be saved as PSD before saving it. SVG SVG ADS does not change SVG data when loading it. Any Image data to be optimization settings are preserved. manipulated with the graphics commands. PDF PDF ADS does not change PDF data when loading it. Document input to be transformed to an image format or manipulated with the document commands. PostScript PostScript ADS does not change PostScript data when loading it. Document input to be EPS PostScript content is saved to the same format that was transformed to an image loaded. or PDF format. XML XML ADS does not change XML data when loading it. Replacement data for You can load XML content in two different ways with SVG content. the loadContent command: you can specify a file that contains the XML content with the source attribute, or you can omit the source attribute and provide the XML data inline within the loadContent element. XMP XMP ADS does not change XMP data when loading it. Replacement metadata values to be added to appropriate types of content. XSL-FO XSL-FO ADS does not change XSL-FO data when loading it. It To transform to PDF. treats it as it does XML data, except that it recognizes it as XSL-FO information, not arbitrary XML. FDF FormData ADS does not change FDF or XFDF data when New or replacement XFDF loading it. It recognizes both formats as Acrobat Form form data or comments Data and loads the data into a FormData content to import into existing holder. Comments as well as form data are stored in PDF content. this format. FormData content is saved to the same format that was loaded.
56 Dec 19, 2003 Adobe Document Server Developers Guide Direct Content Type Conversions ADS Command Basics Converting Content 3
TABLE 3.3 Loading file data with the loadContent command (Continued)
Content File format type Description Typical uses FM, MIF Frame ADS does not change FM or MIF data when loading it. To provide a template for It recognizes both forms of FrameMaker output as XSL-FO content being Frame data and loads it into a Frame content holder. transformed to PDF. Frame content is saved to the same format that was loaded.
Converting Content
Once you have loaded data into ADS with the loadContent command, you can manipulate it in a number of ways. The Adobe Document Server Command Reference contains reference information for all the ADS commands, and identifies which commands work on which type of content. Some commands convert content of one type to content of another type. This section summarizes those conversions and points you to other locations in the documentation where these conversions are discussed in more detail.
Direct Content Type Conversions ADS provides commands for converting some content types to other content types. All of the conversion commands take input content of one type, and output content of a different type, which becomes current. The following table summarizes the available content type conversions, and how to accomplish them.
TABLE 3.4 Direct content type conversions
Direct conversion Command Details Raster ➟ EPS convertRasterToEPS ➟ PDF convertRasterToPDF SVG ➟ Raster convertSVGToRaster The Raster content is marked to be saved as PSD. Optimization settings that were set with the Illustrator Save For Web feature are preserved. ➟ PDF convertSVGToPDF PDF ➟ Raster convertPDFToRaster The Raster content is marked to be saved as PSD, and contains no optimization settings. ➟ EPS convertPDFToEPS
Adobe Document Server Developers Guide Dec 19, 2003 57 ADS Command Basics Commands That Work on One Content Type but Produce Another 3 Converting Content
TABLE 3.4 Direct content type conversions (Continued)
Direct conversion Command Details PostScript ➟ Raster convertPSToRaster The Raster content is marked to be saved EPS as PSD, and contains no optimization settings. ➟ PDF convertPSToPDF
You can perform these conversions in sequence to achieve a conversion for which there is no single explicit command. For example: ● To transform an SVG file to a PostScript file, load the SVG, convert it to PDF with the convertSVGToPDF command, convert the PDF content to EPS, and save with the saveContent command. ● To convert a PostScript file to a TIFF file, load the PostScript file, convert the PostScript content to Raster content, mark the Raster content to be saved as TIFF (see “The Format Flag on Raster Content” on page 62), and save with the saveContent command. ● To convert a PDF file to a JPEG file, load the PDF file, convert the PDF content to Raster content, use the set command to add the JPEG optimization settings, and save with the saveOptimized command.
Commands That Work on One Content Type but Produce Another Most of the ADS commands, other than the conversion commands listed in Table 3.4, produce the same type of content as the type on which they operate. A few commands, however, work on content of one type but produce content of a different type. These commands are listed in Table 3.5.
TABLE 3.5 Commands that work on one content type and produce another
Command Input content type Output content type
imageInfo Raster XML
exportMetadata Raster, SVG, PDF XMP
exportBookmarks PDF XML
exportComments PDF FormData
exportDataObject PDF any type
exportLinks PDF XML
exportFormData PDF FormData
formatXSL XSL-FO PDF (and optionally FM or MIF)
getUsageRights PDF XML
58 Dec 19, 2003 Adobe Document Server Developers Guide Determining Where Result Content is Saved ADS Command Basics Saving Content 3
Saving Content
The saveContent and saveOptimized commands save ADS content to an external file. You can call these commands to save content explicitly at any point in a command set. The contents may be saved to the local file system, or included in a response object if you have invoked ADS from one of the three APIs. Both save commands require the name attribute, which is used to name the file (on the file system) or result (in the response object). If a command set does not contain an explicit save command, ADS automatically saves the current content after the last command has been processed; see “Automatic File Saving” on page 64.
NOTE: Some files written out by ADS may not be binary compatible across different operating systems. For example, if you write a file on a Microsoft® Windows® system, it is not always identical to the same file written out on a Solaris system.
Determining Where Result Content is Saved When you construct a request, you can tell ADS where to save the result files by specifying a result location. This must be a folder on the file system where the ADS process executes the request. You can specify the result location: ● In the interface — On the command line, give the resultLocation argument when you invoke ADS. From the Java, COM, or Perl API, call the resultLocation method when you construct the request. ● In the commands — Set the resultLocation attribute of the commands element.
NOTE: If you specify a result location in both the interface and the commands, the setting in the interface takes precedence. Specifying the result location is optional. If you do not specify a result location, the default behavior for returning results is used. This default behavior varies across interfaces. The following table shows where results are placed in all cases:
TABLE 3.6 Determining the result location
Result Interface location Rule for determining destination
Java API specified The name specified in the save command is interpreted as Perl API a file URI. If it is relative, the value of resultLocation is COM API used as the base. Web service direct not specified Content not saved with an absolute file: URI is returned to the client in a response object, identified by the name specified in the save command. The name must not be a file URI; it must not contain forward or backward slashes or a colon.
Adobe Document Server Developers Guide Dec 19, 2003 59 ADS Command Basics Naming Results 3 Saving Content
TABLE 3.6 Determining the result location (Continued)
Result Interface location Rule for determining destination
The command line specified The name specified in the save command is interpreted as a file URI. If it is relative, the value of resultLocation is used as the base.
not specified The name specified in the save command is interpreted as a file URI. If it is relative, the current working directory of the command line is used as the base URI.
Naming Results If you have a command set that does not contain any save commands, ADS automatically saves the result of the last command. If the content type can be optimized, it uses the saveOptimized command; otherwise it uses the saveContent command. In either case, ADS names the result "Untitled" and appends an appropriate file extension. When you explicitly save current content using a save command, you must specify a name for the result; both the saveContent and saveOptimized commands require the name attribute. The form this attribute value can take depends on how the request was invoked: ● If the request is invoked from one of the APIs and you have not specified a result location, the value of this name must be either an absolute URI (file:///path) or a simple name that does not contain slashes or colons (myfile). An absolute URI causes the result to be written to the local file system; a simple name causes it to be written to the response object. ● In all other cases, the value of the name can be a simple name, a name with a file extension, or a relative or absolute URI, including a filename. For requests submitted from the command line, relative URIs are resolved against the result location, if set, or against the location of the command file. For requests submitted from the APIs or directly to the Web service, relative URIs are allowed only if a result location has been specified, and are resolved relative to that location. Providing Your Own File Extension If you are sure of the file format being saved, and your results are being written to the file system, you can include an appropriate file extension as part of the name you supply. For example:
60 Dec 19, 2003 Adobe Document Server Developers Guide Basic File Saving ADS Command Basics Saving Content 3
If you set appendExtension to true and you also specify a file extension as part of the file name, you get a filename with two extensions. For example, if you save SVG content as follows:
Basic File Saving The saveContent command saves ADS content to the external file system. The following table shows how the saveContent command transforms content to file formats.
TABLE 3.7 Saving content with the saveContent command
Content type File format on save
Raster Raster content is marked to be saved as PSD or TIFF. • If it is marked as PSD, it is saved to a PSD version 7 file (.psd). • If it is marked as TIFF, the saveContent command transforms the content to the TIFF format and saves it to a TIFF version 6 file (.tif).
SVG Written as SVG (.svg), using the version and namespaces with which the content was loaded.
PDF Written as PDF 1.5 (.pdf).
PostScript Written to the format and version from which the content was loaded or created: •PostScript (.ps) • encapsulated PostScript (.eps) • Photoshop-compatible encapsulated PostScript (.eps) New PostScript files created with the convertPDFToEPS or convertRasterToEPS command are written as level 2 EPS.
XML Written as XML (.xml) using the version and namespaces with which the content was loaded.
XMP Written as XMP (.xmp). For details of namespaces used in the file, see Chapter 4, “Working with File Metadata.”
FormData Written to the format and version from which the content was loaded, or that was specified by the format attribute of exportFormData or exportComments: • FDF 1.2 (.fdf) • XFDF (.xfdf), in the XFDF namespace http://ns.adobe.com/xfdf/
Adobe Document Server Developers Guide Dec 19, 2003 61 ADS Command Basics Basic File Saving 3 Saving Content
TABLE 3.7 Saving content with the saveContent command (Continued)
Content type File format on save
XSL-FO Written as XSL-FO (.fo), using the version and namespace with which the content was loaded.
Frame Written to the format and version from which the content was loaded: •MIF (.mif) •FrameMaker (.fm)
The Format Flag on Raster Content A Raster content holder has a format flag that controls the format of the file produced by the saveContent command. When you load a PSD, JPEG, GIF, or PNG file, the flag is set to PSD. When you load a TIFF files, it is set to TIFF. You can change the setting of this flag between loading and saving an image file, with the setFileFormat command. For example, you can load a GIF file and mark it to be saved as a TIFF file, or you can load a TIFF file and mark it to be saved as a PSD file. Similarly, you can convert another content type to Raster, then use setFileFormat to change the format flag, so that the content will be transformed to TIFF on save. Metadata Conversions on Basic Save The saveContent command saves all existing metadata with a file in the XMP format. For PSD and TIFF formats, applicable properties are also written in the EXIF and IPTC formats. Upon save, metadata values in all formats supported by ADS are guaranteed to be consistent. If you do not want metadata saved with a file, you must explicitly remove it from the content before saving, using the removeMetadata or importMetadata command. For more information, see Chapter 4, “Working with File Metadata.”
62 Dec 19, 2003 Adobe Document Server Developers Guide Saving to Optimized Formats ADS Command Basics Saving Content 3
Saving to Optimized Formats You can save Raster, SVG, or PDF content to a Web-optimized file format with the saveOptimized command. The command saves to optimized formats depending on the current content type, as follows:
TABLE 3.8 Saving content with the saveOptimized command
Content type Save behavior
Raster The saveOptimized command saves to one of the optimized image formats — GIF, JPEG, PNG8, PNG24, or WBMP — depending on the optimization settings in the content. The saveOptimized command flattens layers in the current content before creating the result file according to the current optimization settings. ADS uses optimization settings that were set in Photoshop using Save For Web, or set previously in ADS. You can use the optimizeToSize and set commands to modify optimization settings within ADS. Any settings that are not explicitly provided default according to the preferred file format. If the current content does not contain optimization settings, the command writes a GIF file using built-in default optimization settings. The command operates only on images that use RGB color profiles. You can use the convertProfile command to convert the color to an RGB profile.
SVG The saveOptimized command converts SVG content to the Raster format, then saves it in the preferred format using any optimization settings that were set in Illustrator using Save For Web, or set previously in ADS. You can us e t he set command to modify optimization settings within ADS. If the current content does not contain optimization settings, the command writes a GIF file using built-in default optimization settings.
PDF The saveOptimized command saves to PDF 1.5 format optimized for Web use (the "Fast Web View"). This may make it much faster to read the file from a Web site. You cannot set any specific optimization parameters for PDF content.
The following table summarizes the file name extensions that this command assigns for file formats, and the versions of those formats that it writes.
TABLE 3.9 File extensions used by the saveOptimized command
Format Extension Version GIF .gif Written as version 89a. JPEG .jpeg Written as JFIF 1.2. PNG8/24 .png Written according to the PNG 1.2 specification (the PNG file format itself is not versioned). WBMP .wbmp Written as a WAP 1.1 type 0 image. PDF .pdf Written as linearized PDF 1.4.
For more information, see “Saving Optimized Files” on page 112.
Adobe Document Server Developers Guide Dec 19, 2003 63 ADS Command Basics Automatic File Saving 3 Saving Content
Setting Optimization Information There are two ways you can set or modify the optimization information in content before saving it: ● Use the optimizeToSize command to automatically set the preferred optimized file format for an RGB image. This command determines whether GIF or JPEG format results in a smaller file. ● Use the set command to explicitly modify or replace the optimizationSettings element in the content. The optimized save format is determined by the name of the child element you provide. The choices are: – GIFFormat – PNG8Format – PNG24Format – WBMPFormat – JPEGFormat The default optimization file format is GIF. Saving Metadata with Optimized Files In the saveOptimized command, you can use the optional metadata attribute to specify whether to save metadata with an optimized image file, and what metadata formats to save (XMP, EXIF, and/or IPTC). If you do not supply the attribute, no metadata is saved with the image file. (XMP metadata is always saved with PDF files.) You can specify any combination of the supported formats; however, the non-XMP formats apply only to JPEG files. If the file is not being written in JPEG format, those values are ignored. You can include XMP format metadata for any output file. If you specify any non-XMP formats for a JPEG file, the properties appropriate to the format are saved with the file. If you also specify XMP format, all current XMP metadata is saved with the file. Upon save, metadata values in all formats are guaranteed to be consistent. For more information, see Chapter 4, “Working with File Metadata.”
Automatic File Saving After every command in the request has been processed, in the absence of any explicit saveOptimized or saveContent commands, ADS performs an implicit save operation on the current content. Which save command it uses depends on the type of the current content.
Content type Save command used
RGB Raster, SVG, PDF saveOptimized
CMYK Raster, PostScript, XML, XMP, saveContent XSL-FO, FormData, Frame
When a result file is created by an automatic save operation, it is given the name Untitled, and the appropriate file extension is appended.
64 Dec 19, 2003 Adobe Document Server Developers Guide Automatic File Saving ADS Command Basics Referenced Attributes Values 3
When you pass a file to ADS on the command line in the -source argument and do not specify a command file, an automatic save is performed on the file, and the result is saved with the default name in the current working directory or the result location, if specified.
Referenced Attributes Values
ADS defines a special reference function you can use to access named content and retrieve values from it, as long as that content is accessible with abbreviated XPath syntax. You can use such a content reference anywhere as an attribute value. A content reference can be useful for retrieving values from loaded content at run time, when you do not know ahead of time what those values will be. When ADS executes a command containing a content reference, it first evaluates the reference, then passes the result to the command as the attribute value. If the reference does not evaluate to the expected value type, the command reports an error. The syntax for a content reference is as follows: reference(adobe-content:contentName#XPath) The #XPath portion of the specification is optional. If it is not supplied, the expression evaluates to the entire named content. For example, suppose you load and name the following simple XML content:
Adobe Document Server Developers Guide Dec 19, 2003 65 ADS Command Basics Automatic File Saving 3 General Commands
EXAMPLE 3.1 Using a content reference to select an image at run time The following commands load the sample XML shown above from an external source and use the reference syntax to select and operate on the dog image:
General Commands
The following commands report on or affect the state of the system and do not operate on content: ● info: Reports information about the ADS application, such as copyright information and Adobe personnel involved on the project, in XML format. ● version: Reports the current ADS version information in XML format. ● registerMetadataNamespace: Creates an XML namespace for use with metadata, and requests a prefix to be associated with it. For more information, see Chapter 4, “Working with File Metadata.”
66 Dec 19, 2003 Adobe Document Server Developers Guide 4 Working with File Metadata
This chapter describes how ADS deals with metadata in the files that you can load and manipulate. It contains the following sections:
Overview of Metadata starting on page 67 Working with Metadata in ADS starting on page 69 Transformations of Metadata Formats starting on page 78
Overview of Metadata
ADS uses Extensible Metadata Platform technology (XMP) to handle metadata associated with many content types. XMP is a framework for XML metadata exchange and a labeling system for document and digital assets. XMP defines a mechanism for placing metadata in a variety of file formats. ADS can read and write metadata values in both XMP (for Raster, SVG, and PDF content) and in the EXIF and IPTC formats (defined for PSD, TIFF, and JPEG). However, it manages all metadata internally in the XMP format, and you must use the XMP format for modifying metadata. ADS handles the translation to and from XMP and other formats upon load and save; see “Transformations of Metadata Formats” on page 78. When you load a file into ADS, ADS resolves any conflicts in corresponding metadata values from different formats. When you save a file from ADS, metadata values are guaranteed to be consistent in all formats. ADS operates only on document-level metadata. If a file contains component-level metadata (such as metadata stored in an embedded JPG image in a PDF file), ADS preserves it, but does not allow you to access it. ADS supplies commands for extracting and replacing metadata, and for manipulating individual metadata values. See “Working with Metadata in ADS” on page 69.
Metadata and Content Types ADS represents and manipulates metadata in the XMP format. When it loads a file, it translates all supported metadata formats into the XMP format. Properties from each original format go into a specific namespace, so that they can be restored to that format on save. See “Transformations of Metadata Formats” on page 78.
Adobe Document Server Developers Guide Dec 19, 2003 67 Working with File Metadata Creating a Custom Metadata Schema 4 Overview of Metadata
You can extract metadata from a file using the exportMetadata command. The metadata is returned as XMP content. XMP content contains data in the XML Packet format; however, it is not the same as XML content. XMP and XML content cannot be used interchangeably. ● When you save the XMP content, the saveContent command provides the .xmp file extension and saves the file as an XML Packet using the XMP packet wrapper. ● You can reload the saved metadata in another ADS session using the loadContent command, and, if you wish, use it to replace all of the metadata for a file, using the importMetadata command. When ADS loads an XML Packet with the XMP packet wrapper, it treats it as XMP content, rather than XML content. All metadata manipulation operations other than importMetadata act on XMP metadata embedded in content of the various supported types: PDF, Raster, and SVG. The saveContent command automatically transforms the current XMP metadata to all metadata formats supported for the content type, and embeds it in the output file. The saveOptimized command allows you to specify whether or not to write out metadata with the optimized file, and, if you include metadata, which formats to include.
Creating a Custom Metadata Schema ADS defines standard XMP namespaces, and in addition defines namespaces for XMP properties that are created from EXIF– and IPTC–format metadata. See “Metadata Namespaces” on page 80. If you add or modify properties in these namespaces, the save commands can write out that information to the EXIF and IPTC formats. See “Saving Files with Metadata” on page 77. Within ADS, you can register your own metadata namespace that identifies a custom metadata scheme. Before manipulating the metadata, register your namespace with ADS using the registerMetadataNamespace command. The namespace is then recognized throughout the current ADS request, and you can add or modify properties in that namespace, using the metadata manipulation commands. When ADS writes out XMP metadata, by itself or embedded in a file, each namespace is associated with a prefix in the XML Packet. For example, the following XML Packet fragment specifies that the namespace http://ns.adobe.com/photoshop/1.0/ is associated with the prefix photoshop, as in the following code fragment:
68 Dec 19, 2003 Adobe Document Server Developers Guide Extracting Metadata from Loaded Content Working with File Metadata Working with Metadata in ADS 4
Working with Metadata in ADS
When you load a file into ADS, it creates an XMP representation of that file’s metadata, translating properties as needed from IPTC and EXIF metadata formats. ● You can extract metadata from a loaded file and write it out to an XMP file. ● You can modify the metadata in a loaded file by adding or deleting properties, changing property values, or completely replacing the metadata with a new XML Packet.
Extracting Metadata from Loaded Content To extract metadata in ADS content, use the exportMetadata command. This command copies all of the existing XMP-format document-level metadata for the current content into a new XMP content holder, which contains the data in the XML Packet format. The command makes the new XMP content current. The XMP contains the namespaces required to preserve metadata that was loaded from other supported formats (IPTC and EXIF), as well any other namespaces used in the file. Because ADS does not support program-logic branching in its command syntax, you cannot make metadata-based decisions inside ADS. You can, however, extract and write out metadata to a separate file, read that file outside ADS, and make decisions based on the values. Once you have extracted metadata from ADS content, you can use the saveContent command to save the extracted XMP data as an XML Packet. For example:
NOTE: The actual information returned by the exportMetadata command varies by the original file type of the content and the application (and version) that last touched the file before it was loaded into ADS.
Adobe Document Server Developers Guide Dec 19, 2003 69 Working with File Metadata Extracting Metadata from Loaded Content 4 Working with Metadata in ADS
EXAMPLE 4.1 Metadata from IPTC format The following example shows part of the result of exporting metadata from a PSD file, in which much of the metadata was expressed in IPTC format. The output is an XML Packet. The IPTC metadata is reflected in the photoshop namespace.
70 Dec 19, 2003 Adobe Document Server Developers Guide Extracting Metadata from Loaded Content Working with File Metadata Working with Metadata in ADS 4
Adobe Document Server Developers Guide Dec 19, 2003 71 Working with File Metadata Extracting Metadata from Loaded Content 4 Working with Metadata in ADS
EXAMPLE 4.2 Metadata from EXIF format The following is an example of the XMP representation of metadata that was originally in the EXIF format:
72 Dec 19, 2003 Adobe Document Server Developers Guide Extracting Metadata from Loaded Content Working with File Metadata Working with Metadata in ADS 4
EXAMPLE 4.3 XMP Metadata in a PDF file The following is an example of XMP metadata extracted from PDF content:
Adobe Document Server Developers Guide Dec 19, 2003 73 Working with File Metadata Modifying Metadata in Loaded Content 4 Working with Metadata in ADS
Modifying Metadata in Loaded Content You can modify the metadata in a loaded file by adding or deleting properties, changing property values, or completely replacing the metadata with a new XML Packet. Adding and Modifying Non-Structured Properties To add a new non-structured (scalar) property and its value, or to change the value of an existing property, use the command setMetadata. When you add new metadata in ADS using the setMetadata command, it is created according to the W3C Resource Description Framework (RDF). For more information on this syntax, see http://www.w3.org/TR/1999/REC-rdf-syntax-19990222. ADS uses a set of aliases defined in the XMP specification for equivalent properties. Any alias can be used to refer to the source property, which contains the value. When you specify an alias as the property to be modified, ADS modifies the source. (See “Metadata Aliases” on page 81.)
EXAMPLE 4.4 Modifying a metadata property This example loads a PSD file, sets the metadata property AuthorsPosition to the value artist, then saves the content to a new PSD file. The file is saved with embedded XMP, EXIF, and IPTC metadata. The new property value is in the namespace for IPTC, so the new value will be seen both in the XMP data and in the IPTC metadata that you can view in Photoshop, as
74 Dec 19, 2003 Adobe Document Server Developers Guide Modifying Metadata in Loaded Content Working with File Metadata Working with Metadata in ADS 4
EXAMPLE 4.5 Creating and adding to a structured property This example loads a PSD file and creates a new structured metadata property named Keywords in the standard XMP namespace. The new property is of type bag, indicating an unordered list of items. The first item is Keyword1. The example then adds a second item to the property, Keyword2, appending it to the first item (regardless of what that item was). It then saves the Raster content as a new PSD file (with embedded XMP, IPTC, and EXIF metadata), changes the value of the second Keywords item, and saves the file with the new value.
Adobe Document Server Developers Guide Dec 19, 2003 75 Working with File Metadata Modifying Metadata in Loaded Content 4 Working with Metadata in ADS
Replacing Metadata You can completely replace the metadata for the current content with a new set of properties, with the importMetadata command. All metadata associated with the content is removed and replaced with the new XML Packet that you provide. You can specify the new XML Packet in one of several ways, as shown in the next three examples.
EXAMPLE 4.6 Streaming in replacement metadata in the importMetadata command This example loads the XML Packet inline between importMetadata tags.
NOTE: You cannot load XMP data inline into ADS using loadContent. The loadContent command would interpret the XML Packet as XML and store it as XML content, which you cannot pass to importMetadata.
EXAMPLE 4.7 Loading replacement metadata from a file This example loads the XML Packet from an XMP file and names it using the out attribute of loadContent. It is stored as XMP content. You then refer to the named XMP content in the source attribute of importMetadata.
76 Dec 19, 2003 Adobe Document Server Developers Guide Saving Files with Metadata Working with File Metadata Working with Metadata in ADS 4
EXAMPLE 4.8 Copying metadata from one file to another This example extracts and stores metadata from one PSD file, then loads another PSD file. It refers to the stored XMP content as the replacement value for metadata in the new current content.
Saving Files with Metadata When you save a file with the saveContent command, ADS writes out all of the current metadata with the file in the XMP format. If there was any metadata transformed from other formats on load, it is copied back to that format on save. Because the load process resolved all conflicts between different formats, metadata values are guaranteed to be consistent in all formats when you save a file from ADS. ADS derives some metadata values automatically (see “Automatic Metadata Updates” on page 82). These values are saved along with values that have been preserved from load or explicitly set in ADS. If you do not want to save a metadata property with a file, use the removeMetadata command to remove it before saving the file. However, you cannot remove those metadata properties that are automatically updated by ADS. Specifying Formats for Optimized Image Files When you save optimized image files, you can specify whether to save metadata with the files, and which formats to save it in. To do this, use the metadata attribute of the saveOptimized command. The metadata attribute takes a list of supported metadata formats to save, separated by spaces. You can give any combination of the three formats, or none. If you do not supply the attribute, or if you give an empty string, the command does not save any metadata with the file. The three supported formats are XMP, EXIF, and IPTC. Of the optimized file types, only JPEG files can be written with EXIF and/or IPTC metadata. If you specify a format that is not supported for the type of file being saved, that attribute value is ignored. The optimization settings for the JPEG file format also include an embedMetadata attribute. (See the chapter “Accessing Raster Content” in the Adobe Document Server XML Grammars Reference.) If this attribute is true, IPTC metadata is embedded in the file regardless of the value of the saveOptimized metadata attribute. In this case, you can use the saveOptimized metadata attribute to specify XMP and/or EXIF in addition to the IPTC format.
Adobe Document Server Developers Guide Dec 19, 2003 77 Working with File Metadata Supported Metadata Formats 4 Transformations of Metadata Formats
EXAMPLE 4.9 Saving an optimized image with a new metadata property
Transformations of Metadata Formats
When you load files into ADS, ADS uses a set of aliases and precedence rules to resolve equivalent metadata properties from different formats to a single value. It automatically derives and adds certain metadata values that reflect its own manipulation of the files. When you save content containing metadata, the saveContent command transforms the information into all of the metadata formats that apply to the file format, and saves them along with the XMP. This ensures that metadata within and saved from ADS is consistent across all formats. The saveOptimized command similarly transforms the metadata into those formats that you specify, if they apply to the saved file format. This section describes: ● Metadata formats that ADS supports for each file type. ● The namespaces ADS uses to represent non-XMP metadata. ● The aliases that define equivalencies among namespaces. ● The metadata values that ADS derives automatically. ● The precedence rules ADS uses to resolve property value conflicts.
Supported Metadata Formats Table 4.1 shows the metadata formats that ADS supports for each file format. It describes how ADS treats the metadata in each kind of file upon load, and how ADS treats metadata when content loaded from one format is converted to a different format.
78 Dec 19, 2003 Adobe Document Server Developers Guide Supported Metadata Formats Working with File Metadata Transformations of Metadata Formats 4
TABLE 4.1 Supported metadata formats
Metadata File format formats Metadata support on load, save, and convert
PSD XMP, IPTC, EXIF ADS preserves EXIF, IPTC and XMP metadata on load. •The saveContent command writes out all supported JPEG XMP, IPTC, EXIF metadata formats for PSD and TIFF files. TIFF XMP, IPTC, EXIF •The saveOptimized command writes out only the metadata formats you specify that are supported for the GIF XMP destination file format. Only the JPEG format supports EXIF and IPTC formats. The optimization settings for PNG XMP JPEG also affect whether IPTC metadata is saved with the file.
SVG XMP ADS preserves the document-level XMP metadata in SVG files on load, but ignores metadata stored in other metadata elements. When you convert SVG content to PDF content, some of the PDF metadata is updated (see “Automatic Metadata Updates” on page 82). Metadata embedded in images that are referenced in the SVG remains inside the image in the resulting PDF file, but is not accessible to ADS.
PDF XMP, PDF 1.5 The rules for XMP metadata propagation to the PDF Info dictionary are described in the XMP Framework documentation. Upon load, ADS updates the NPages property in the namespace http://ns.adobe.com/xap/1.0/t/pg/ to reflect the number of pages in the document. When you use the convertPDFToRaster command, the document-level metadata is preserved, but any metadata associated with embedded images is lost. For operations that combine multiple PDF documents, or multiple portions of PDF documents, the metadata of the destination document is preserved, and the metadata for the donor document is discarded. Metadata carried inside images in both documents is preserved. If necessary, you can retrieve desired metadata before the conversion operation, then restore it after the operation.
PhotoShop EPS XMP When you convert an EPS file created by Photoshop to Raster format, XMP metadata is preserved and can be saved with the file. When you convert Raster content to Photoshop EPS, all metadata is preserved in XMP format and is saved by the saveContent command.
Adobe Document Server Developers Guide Dec 19, 2003 79 Working with File Metadata Metadata Namespaces 4 Transformations of Metadata Formats
TABLE 4.1 Supported metadata formats (Continued)
Metadata File format formats Metadata support on load, save, and convert
generic EPS, -- ADS cannot access metadata in generic EPS or PostScript PostScript files, even when the metadata is stored in XMP format. Any metadata that was in the loaded file is saved with the file by the saveContent command. When you convert EPS files that were not created by Photoshop to Raster content, ADS does not preserve metadata, even if it is in XMP format.
XSL-FO XMP When you use the formatXSL command to create PDF content, XMP metadata in the XSL-FO file is preserved in the PDF.
Metadata Namespaces ADS uses the following preregistered XMP namespaces:
TABLE 4.2 Preregistered namespaces
Namespace Prefix
http://ns.adobe.com/xap/1.0/ xap http://ns.adobe.com/xap/1.0/g/ xapG http://ns.adobe.com/xap/1.0/g/img/ xapGImg http://ns.adobe.com/xap/1.0/dyn/ xapDyn http://ns.adobe.com/xap/1.0/dyn/a/ xapDynA http://ns.adobe.com/xap/1.0/dyn/v/ xapDynV http://ns.adobe.com/xap/1.0/t/ xapT http://ns.adobe.com/xap/1.0/t/pg/ xapTPg http://ns.adobe.com/xap/1.0/rights/ xapRights http://ns.adobe.com/xap/1.0/mm/ xapMM http://ns.adobe.com/xap/1.0/s/ xapS http://ns.adobe.com/xap/1.0/bj/ xapBJ http://ns.adobe.com/pdf/1.3/ pdf http://purl.org/dc/elements/1.1/ dc http://ns.adobe.com/tiff/1.0 tiff http://ns.adobe.com/exif/1.0 exif http://ns.adobe.com/photoshop/1.0/ photoshop
80 Dec 19, 2003 Adobe Document Server Developers Guide Metadata Aliases Working with File Metadata Transformations of Metadata Formats 4
When you load a file containing metadata into ADS, ADS transforms properties from EXIF and IPTC formats into XMP equivalents in their respective namespaces. The properties can be transformed back to the original format upon save. ● Properties read from the EXIF format may be in the tiff or exif namespace. ADS base-64-encodes some EXIF values. In these cases, the value is prefaced with the string 'base64,'. ● Properties in the photoshop namespace are equivalent to fields available through the PhotoShop File Info dialog, which PhotoShop may store as IPTC or XMP or both. Because IPTC metadata is often stored without any encoding information, ADS uses the following rules to map unencoded character values when converting between IPTC and XMP: – Invalid 7-bit characters appearing in IPTC fields (that is, non-graphic characters other than space, newline, carriage return, and tab) are mapped to a question mark when converted to XMP. – 8-bit characters appearing in IPTC fields without encoding information are mapped to a question mark when converted to XMP. (IPTC allows 8-bit encodings to be specified, but Photoshop does not.) – Non-ASCII characters in XMP fields are converted to an ASCII character (question mark or appropriate fallback character) when mapping from XMP to IPTC.
Metadata Aliases To ensure consistency of metadata, ADS uses equivalencies among the metadata formats that it supports. The XMP toolkit defines aliases from equivalent properties in other namespaces to a source property, usually in the Dublin Core (dc) namespace. When ADS reads in metadata from an aliased property, it stores the value in the source property. You can refer to a property by any of its aliases. When you specify an alias in a metadata command, ADS performs the operation on the source property for that alias. For example, the XMP property dc:description is the source for the aliased fields xap:Description, tiff:imageDescription, and photoshop:Caption. When ADS reads a file that has any one of these values, it creates the source property (dc:description). The source property contains the value, regardless of where the value came from. The aliases do not have values, but simply point to the source, dc:description. The following fragment of an XML Packet illustrates how aliases are shown at the beginning of the packet:
Adobe Document Server Developers Guide Dec 19, 2003 81 Working with File Metadata Automatic Metadata Updates 4 Transformations of Metadata Formats
Automatic Metadata Updates When you save content from ADS, some internal metadata properties such as xap:MetadataDate are automatically updated. Other metadata values, such as the size or bit depth of an image, that are derived from the data, cannot be set explicitly, but may be updated automatically on save. Derived properties are not automatically copied to the IPTC or EXIF metadata formats. If metadata is not present in either IPTC or EXIF format in the source document, it is not present in the output in that format, unless you specifically add it using ADS commands. The following table lists metadata properties that are automatically updated during format conversion and file save operations.
TABLE 4.3 Metadata fields modified by ADS
Command Fields modified
saveContent (SVG) xap:Format xap:MetaDataDate xap:ModifyDate
saveContent (PDF) pdf:ModDate xap:Format xap:MetaDataDate xap:ModifyDate
saveContent (EPS) xap:Format xap:MetaDataDate xap:ModifyDate
NOTE: Metadata is not saved with PostScript content that does not conform to PhotoShop-compatible encapsulated PostScript.
saveContent (PSD) stDim:w saveOptimized (JPG, GIF, PNG) stDim:h xap:Format xap:MetaDataDate xap:ModifyDate
saveContent (TIFF) stDim:w stDim:h tiff:BitsPerSample tiff:ColorSpace tiff:ResolutionUnit tiff:SamplesPerPixel tiff:XResolution tiff:YResolution xap:Format xap:MetaDataDate xap:ModifyDate
82 Dec 19, 2003 Adobe Document Server Developers Guide Resolving Metadata Inconsistency Working with File Metadata Transformations of Metadata Formats 4
TABLE 4.3 Metadata fields modified by ADS (Continued)
Command Fields modified
formatXSL pdf:Producer convertSVGToPDF convertRasterToPDF convertPSToPDF
convertPDFToEPS none convertPDFToRaster convertPSToRaster convertRasterToEPS convertSVGToRaster convertTo (SVG to Raster)
Resolving Metadata Inconsistency Some tools read and write only a particular format of metadata, ignoring any others. If such a tool has modified the metadata at any point, it can become inconsistent — that is, equivalent properties can have different values. If a file contains inconsistent metadata, ADS resolves the inconsistency when you load the file, so that metadata in loaded content and metadata in files that you save from ADS is always consistent. If values of equivalent properties are inconsistent between formats, ADS applies precedence rules to determine the final value. In general, if a file contains XMP metadata, ADS uses the XMP property value, unless it can determine that an equivalent property in another format has been updated more recently. The following table describes the rules that govern which value takes precedence.
TABLE 4.4 Metadata format precedence for file types
File format Metadata precedence rules
PSD, TIFF ADS reads information in the following order, replacing earlier values with later values: • kCaptionID image resource For older Photoshop files, the caption data is read from the image resource ‘1008’ (kOldCaptionID) or ‘1020’ (kPrintCaptionID). It cannot appear in both. • Image Description Tag (TIFF only) • IPTC-NAA Tag (TIFF only) TIFF information is read before image resource information, so an edit to the TIFF information is not recognized unless the image resource information is removed. For Photoshop 6.5 XMP Data, the kCaptionID image resource is written out with a digest signature. The digest is regenerated. If it does not match, then the XMP information is dropped. Otherwise the XMP information is used instead of all previous data.
Adobe Document Server Developers Guide Dec 19, 2003 83 Working with File Metadata Resolving Metadata Inconsistency 4 Transformations of Metadata Formats
TABLE 4.4 Metadata format precedence for file types
File format Metadata precedence rules
SVG ADS reads and preserves only XMP metadata.
PDF PDF files can have metadata stored in two places: the Info dictionary, and as XMP. ADS parses any existing XMP metadata first. If the Info dictionary information is older than the XMP data, ADS ignores it. If the Info dictionary information is newer, ADS uses it. • Keys that correspond with XMP keys go into the pdf namespace. • Keys that do not correspond with XMP go into the pdfx namespace.
84 Dec 19, 2003 Adobe Document Server Developers Guide Part III
Graphics
Adobe Document Server Developers Guide Dec 19, 2003 85 86 Dec 19, 2003 Adobe Document Server Developers Guide 5 Basic Image Manipulations
This chapter describes how to perform various image manipulation tasks using ADS commands, how to convert document formats to image formats, and how to save images to various optimized file formats. It also discusses the versions of other Adobe products (such as Illustrator and Photoshop) in which image file features were added, to help you in planning how to use ADS with legacy image source files. This chapter contains the following sections:
Overview starting on page 87 Sizing and Cropping Images starting on page 88 Layer Manipulations starting on page 95 Working with Color starting on page 99 Modifying Image Data starting on page 103 Accessing Raster Content starting on page 109 Treating PostScript and PDF Content as Images starting on page 112 Saving Optimized Files starting on page 112 Legacy File Limitations starting on page 118
Overview
You can use ADS to perform programmatic manipulations of images in a number of ways: ● Use specific image-related commands to do the following: – Change the size of an image, crop or trim it, or change its orientation. – Add, remove, position, or flatten layers. – Change the color mapping in the image. – Replace a pixel or text layer. This chapter provides information and examples to help with these tasks. (For detailed information on each command, see the Adobe Document Server Command Reference.) ● Use the more general set command to manipulate some elements of the Raster content directly, using the ADS Raster content model. See the chapter “Accessing Raster Content” in the Adobe Document Server XML Grammars Reference. ● Use automatic or explicit variable replacement to provide new values at run time for variables you have defined in a PSD or SVG file using Photoshop or Illustrator. For details, see Chapter 7, “Replacing Variables in SVG and PSD Files.”
Adobe Document Server Developers Guide Dec 19, 2003 87 Basic Image Manipulations Changing the Canvas Size 5 Sizing and Cropping Images
ADS transforms non-PSD image files into the internal, PSD-like Raster format on load, so you can manipulate all images as if they had originated in the PSD format. You can convert Raster content to other kinds of content, and save Raster content to a variety of file formats. For more information on converting Raster content to and from other content types and file formats, see: ● “Accessing Raster Content” on page 109 ● “Saving Optimized Files” on page 112 ● “Converting Content” on page 57 and “Saving Content” on page 59 You can load SVG content from a file, or inline in a loadContent command. SVG can contain image references or embedded images in a variety of formats. Some of the information in this chapter applies to SVG, but most is about Raster content. For more information on SVG, see Chapter 9, “Creating Dynamic Graphs in SVG Files” and Chapter 8, “Operations Specific to SVG Files.”
Sizing and Cropping Images
ADS provides commands that you can use to: ● Increase or decrease the size of the image canvas by adding or removing border pixels, or by cropping any pixels outside the interesting area. ● Change the overall image size by setting new pixel dimensions, document dimensions, resolution, or some combination.
Changing the Canvas Size ADS provides commands to change the canvas size by adding or removing work space around an existing image. They adjust the size with reference only to the outside dimensions, not with reference to the image area. The canvas size commands can either increase or decrease the canvas size. ● canvasSize command: Specify a new absolute width and height for the canvas. ● canvasSizeRelative command: Specify a new width and height relative to the original width and height of the canvas. If you increase the canvas size, added canvas appears transparent if the image does not have a background layer. If the image does have a background layer, then added pixels appear opaque white.
88 Dec 19, 2003 Adobe Document Server Developers Guide Changing the Canvas Size Basic Image Manipulations Sizing and Cropping Images 5
EXAMPLE 5.1 Increasing canvas size by adding a border This sample increases the canvas size of the guitar image to 300 by 600 pixels. It centers the original image by adding equal numbers of pixels to the top and bottom, and to the left and right. Because this image does not have a background layer, added canvas pixels are transparent.
EXAMPLE 5.2 Trimming an image This sample first performs a default trimming operation on the guitar image, trimming unneeded transparent pixels from all edges of the background to make the image fill the canvas, and reduce the file size. The second trim command further trims the image by removing pixels on the left and right sides that are of the top left color.
Adobe Document Server Developers Guide Dec 19, 2003 89 Basic Image Manipulations Changing Image Size 5 Sizing and Cropping Images
EXAMPLE 5.3 Applying a clipping path This sample flattens the layers in the guitar image so that the clipping path can be applied to the entire image. It retains the clipping path information in the result.
Changing Image Size The ADS imageSize command directly parallels the Photoshop image size command. Use it to increase or reduce the total image size. You might resize an image, for example, to create a thumbnail, medium, and large version for a Web-based retail catalog. This can be a complex operation, in which you make choices that affect the image quality. To modify the image size, you specify variables in the fundamental size equation: number_of_pixels = measured_size * resolution The command has optional attributes for providing a width or height in pixels, a document width or height in a measurement such as inches or centimeters, and a specific resolution. You can modify only the size, only the resolution, or both the size and resolution. If you want to change both size and resolution, it is best to do so in one command, to avoid unnecessary resampling that could occur if the two were run as distinct operations. Specifying values for all three variables in either width or height overconstrains the equation. Unless the values fit the equation perfectly, this causes an error. Fractional numbers in computer systems are often not exactly represented and can cause unexpected errors in overconstrained conditions. It is recommended that you do not specify all three variables. Unless you specify otherwise, the command maintains the aspect ratio of the original image. If you specify only width, proportions are constrained by the width. If you specify only height, proportions are constrained by the height. If you specify both height and width, proportions are constrained by the smaller value. For details of the attribute names and values, see the imageSize command in the Adobe Document Server Command Reference.
90 Dec 19, 2003 Adobe Document Server Developers Guide Changing Image Size Basic Image Manipulations Sizing and Cropping Images 5
EXAMPLE 5.4 Making successive size modifications on the same image This sample loads the guitar.psd file, containing a guitar image that is 205 pixels by 511 pixels, and performs a series of size transformations. Each transformation is numbered and described below.
EXAMPLE 5.5 Changing the resolution of an image This sample loads the logo.psd file, containing an image that is 200 by 200 pixels, with a resolution of 72 DPI. It performs a series of transformations, specifying a new resolution each time. Each command allows constrainProportions to default to true, maintaining the aspect ratio. Depending on the other parameters, each resolution change has a different effect on the pixel and document size. Each change is numbered and described below.
Adobe Document Server Developers Guide Dec 19, 2003 91 Basic Image Manipulations Changing Image Size 5 Sizing and Cropping Images
1. Reducing the resolution to 300 DPI and allowing resampling leaves the document size unchanged, but reduces the pixel size to 139x139. 2. Reducing the resolution to 300 DPI and without resampling changes the document size to 4x4 inches, leaving the pixel size unchanged. 3. Increasing the resolution to 96 DPI and reducing the document width to 1.5 inches reduces the document height to 1.5 inches, and the pixel size to 144x144. 4. Increasing the resolution to 96 DPI and reducing the pixel width to 100 pixels reduces the pixel height to 100 pixels, and the document size to 1.042x1.042 inches. Scaling Policies Both the imageSize and replacePixels commands allow you to set a scaling policy. The scaling policy determines whether and how to limit the maximum or minimum size of the resized image. ● If the scaling policy is free (the default), then the resulting size will have the largest width and height possible such that neither exceeds the width and height of the target size and the aspect ratio is preserved. For example, a 1x2 pixel image with a target size of 4x4 will have a resulting size of 2x4. If either width or height is omitted, the resulting image will have exactly the height or width specified. The size of the image in the omitted dimension is scaled as appropriate to maintain the aspect ratio of the image. (Omitting both width and height results in no change to the size of the image.) ● If the scaling policy is doNotEnlarge then the actual target size of the image is the smallest of the specified target size and the original image size. This is useful when shrinking a set of images of unknown size to some maximum target size while not enlarging images that are already sufficiently small. For example, if a set of images with sizes 1x1, 10x10, and 100x100 were resized to 20x20 with constrainProportions="true" and scalePolicy="doNotEnlarge", the resulting image sizes would be 1x1, 10x10, and 20x20. ● If the scaling policy is doNotShrink then the actual target size of the image is the largest of the specified target size and the original image. This is useful when enlarging a set of images of unknown size to some minimum target size while not shrinking images that are already sufficiently large. For example, if a set of images with sizes 1x1, 10x10, and 100x100 were resized to 20x20 with constrainProportions="true" and scalePolicy="doNotShrink", the resulting image sizes would be 20x20, 20x20, and 100x100.
92 Dec 19, 2003 Adobe Document Server Developers Guide Changing Image Size Basic Image Manipulations Sizing and Cropping Images 5
EXAMPLE 5.6 The effects of attempted size changes on different images Suppose you have the following images (not shown to scale):
Image A: Image B: Image C 1in x 4in, 50 x 200 pixels 6in x 2in, 300 x100 pixels 2in x 2in, 400 x 400 pixels dpi = 50 dpi = 50 dpi = 200
The following command examples with scaling policies and proportion constraints have different effects when applied to the different images, as shown. 1
Image A Image B Image C No change in dimensions, since Size changes to: Size changes to: modifying the width to 100 100 x 33 pixels 100 x 100 pixels would enlarge the pixel 2 x .66 inches 0.5 x 0.5 inches dimensions, which is prevented The scale policy allows the by the scale policy. image to become smaller, and the resolution remains the same.
2
Image A Image B Image C No change in dimensions. To No change in dimensions. The No change in dimensions. The maintain the proportions, the new image would be 2 x .66 command accepts the largest command tries to fit the image inches, 100 x 33 pixels. This values that fit in the box, which into the specified 2 x 3 inch box, would shrink the pixel are the current values of 2 x 2 which would result in an image dimensions, which is prevented inches. of 0.75 x 3 inches, 37 x 150 by the scale policy. pixels. This would shrink the pixel dimensions, which is prevented by the scale policy.
Adobe Document Server Developers Guide Dec 19, 2003 93 Basic Image Manipulations Changing Image Size 5 Sizing and Cropping Images
3
Image A Image B Image C Size changes to: No change in dimensions. The No change in dimensions. The 1.5 x 6 inches current 6 x 2 inch image fits in new size would be 6 x 6 inches, 75 x 300 pixels the specified 6 x 6 inch box. 300 x 300 pixels, which would Proportions and resolution are shrink the pixel dimensions, Both the pixel and document retained. which is prevented by the scale size are allowed to enlarge. policy.
4
Image A Image B Image C No change in dimensions. At 50 Size changes to: Size changes to: DPI, the new box would be 200 x 66 pixels, which fits the 200 x 200 pixels, which fits the 200 x 300 pixels. To maintain constraining box of 200 x 300 constraining box of 200 x 1200 proportions, the new size would pixels. pixels. be 75 x 300 pixels, which would 4 x 1.16 inches, which 1 x 1 inches, which maintains enlarge the pixel dimensions, maintains 50 DPI resolution. 200 DPI resolution. which is prevented by the scale policy.
Sharpening an Image After Resizing The unsharpMask command applies a traditional film compositing technique to sharpen edges in an RGB image. (This command does not work for CMYK images). The procedure corrects blurring introduced during photographing, scanning, resampling, or printing. It is useful for images intended for both print and online viewing. In a Web-oriented workflow, this command is very effective at restoring sharpness to images that were scaled down with the imageSize command. The unsharpMask command works on one layer at a time. If the image is not in a single layer, and if you want to sharpen multiple layers in a single pass, you must first flatten the image using the flatten command. The unsharpMask command allows you to specify a threshold, a radius and an amount. ● The threshold determines how different the brightness values between two pixels must be before they are considered edge pixels. Adjusting the threshold helps you to avoid sharpening the photographic grain in high-resolution scans. This is unlikely to be a problem at on-screen resolution, so it is best to use the default value of 0 for online images. ● The radius is the number of pixels surrounding the edge pixels that are affected by the sharpening operation. This can be an integer between 0 and 255. The default value, 1, is recommended for online images.
94 Dec 19, 2003 Adobe Document Server Developers Guide Referring to Layers Basic Image Manipulations Layer Manipulations 5
● The amount is the amount by which the command increases contrast for the affected pixels. This can be an integer between 1 and 500. The default is 50, and an amount between 50 and 120 is recommended for online images.
EXAMPLE 5.7 Resizing an image and sharpening edges This example loads a PSD image with multiple layers, resizes it, flattens it, and then sharpens the edges with a threshold setting of 0, a radius of 1.5, and the amount to sharpen set to 100. It then saves the modified image.
Layer Manipulations
ADS provides commands that you can use to manipulate image layers programmatically. You can add or delete layers (addLayer, deleteLayer), move a layer (setLayerPosition), or merge multiple layers into a single layer (flatten). In addition, you can use the set command to change the opacity and visibility of individual layers or of layer sets.
Referring to Layers Layer sets and layers are represented by the layerSet and layer elements. ● A layer element for a layer that is not in a layer set is a direct child of the root psd element. ● If there is a layer set, the layerSet element is a direct child of the root psd element, and the member layers are layer subelements of layerSet. In any command that take a layer attribute and in the target attribute of the set command you can reference layer and layerSet elements by index or by name, using the abbreviated XPath syntax. If there are layer sets, you must include the layer set in the XPath layer reference. For example:
/psd/layerSet[@name='myGroup']/layer[1] Refers to the first layer of a layer set named myGroup. /psd/layer[@name='grid'] Refers to a layer by name. /psd/layer[1] Refers to the bottommost layer by number. /psd/layer[last()] Refers to the topmost layer.
Adobe Document Server Developers Guide Dec 19, 2003 95 Basic Image Manipulations Setting Layer Visibility and Opacity 5 Layer Manipulations
/psd/layerSet[last()]/@opacity Refers to the opacity of the entire topmost layer set. /psd/layerSet[1]/@opacity Refers to the opacity of the entire bottommost layer set.
You cannot change the names of layers or layer sets with the set command; you must use Adobe Photoshop to change layer or layer set names. File and Layer Naming Conventions When preparing files in Photoshop for use with ADS, you can use a naming convention for both your PSD templates, and the layers and layer sets within a PSD template. A naming convention can make it easier to remember and reference file and layer names. Your naming convention should take ADS naming rules into account: ● Template file names cannot contain double-byte characters, although text within a text layer can contain double-byte characters. ● Template file names should contain only ASCII text. Avoid spaces in template file names. ● The maximum length for layer and layer set names is 255 characters. ADS truncates any characters beyond this limit and reports a warning to the error log. ● Referencing layers by name is easier and less error-prone if the layer name does not contain certain special characters, such as ampersands, quotes, or spaces. In particular, ADS cannot address layer or layer set names that include a dot character.
Setting Layer Visibility and Opacity You can use the set command to access layers and layer sets directly in order to set their visibility and opacity. Both layer and layerSet elements have visibility attributes. When a layer set is hidden, all of its member layers are also hidden, but when it is visible, the visibility of each layer is determined by its own visibility setting. Similarly, both layer and layerSet elements have opacity attributes. The opacity value is a floating-point number between 0 and 1. An opacity of 0 is completely transparent, and an opacity of 1.0 is completely opaque. When a layer is part of a layer set, the layer element’s own opacity value is interpreted as a percentage of the layer set’s opacity. The colorOverlay element can have an opacity attribute as well. This value determines the degree to which the overlay color replaces the layer color. A value of 1.0 means that it replaces the layer color entirely, and a value of 0 means that the original layer color is unchanged. The layer and layer set opacity values determine how visible the layer is after the color is modified by the color overlay.
96 Dec 19, 2003 Adobe Document Server Developers Guide Flattening Layers Basic Image Manipulations Layer Manipulations 5
EXAMPLE 5.8 Setting layer and layer-set visibility This example hides the entire layer set named set1 by setting the visibility attribute of the layerSet element, and saves the image to a GIF file. After saving the first version, it makes the layer set visible again, but hides one of the member layers.
EXAMPLE 5.9 Setting layer opacity This example sets the opacity of the layer named green to 0.1, making that layer almost transparent.
Flattening Layers You can use the flatten command to compress all image layers into a single layer. When you do this, all visible layers are merged into the background, while hidden layers are discarded. After you flatten an image, you can no longer access individual layers. You typically flatten an image in order to apply a single-layer command to the entire image. For example, you might flatten an image before applying one of the following commands: unsharpMask autoContrast autoLevels applyClipPath
Adobe Document Server Developers Guide Dec 19, 2003 97 Basic Image Manipulations Layers in Images from Other Formats 5 Layer Manipulations
Layers in Images from Other Formats Layers are a feature of PSD images. When you load files from other image formats, or convert them to Raster from a document format (PDF or PostScript), ADS transforms them into the PSD-like internal Raster format, and stores all of the image information in a single, unnamed layer. Even if the image did not originally contain layers, you must refer to this layer to apply some image commands. For example,
Layer and Layer Set Support in Versions of Photoshop
● Layers were introduced in Photoshop version 3.0. PSD files created in earlier versions contain only one layer. ● Unicode layer names were introduced in Photoshop 5.0. If the file was created in Photoshop 5.0 or later, and if the layer name contains non-ASCII characters, ADS can only locate that layer when it is referenced with an index number, for example, '/psd/layer[3]'. ● Layer sets were introduced in Photoshop version 6.0. You must use Photoshop version 6.0 or later to create and maintain layer sets in the PSD template files. ADS cannot add layer sets to an existing PSD; it can only set the visibility and opacity attributes of existing layer sets. ● Editable text layers first appeared in Photoshop version 5.0. To create PSD files with text layers for ADS to replace, you must use Photoshop version 5.0 or later. Multi-styled, multicolored text was not supported in Photoshop until version 6.0. You can use ADS to add text layer information to an earlier version file for use with a later version of Photoshop. ● The color overlay layer style was added in Photoshop version 5.5. ADS can create a color overlay effect on any layer in any PSD file. However, to modify an existing color overlay effect, you must use Photoshop version 5.5 or later to create the template file. For more information on feature support in older versions of Adobe applications, see “Legacy File Limitations” on page 118.
98 Dec 19, 2003 Adobe Document Server Developers Guide Manipulating Color Profiles Directly Basic Image Manipulations Working with Color 5
Working with Color
An International Color Consortium (ICC) color profile maps pixel data to standard colors for a particular device, so that when an image is displayed on that device, the colors appear correctly. When you create a color image using a digital device, it can have the profile of that device embedded in it. To display it correctly on a different device, you would convert the color pixel data from the original profile to that of the display device. ADS supports the RGB and CMYK color spaces. (It reads grayscale, and converts it to RGB internally.) The RGB color space is used for screen display, and the CMYK color space is used for print images. You can convert an image from one color space to another; for example, you would convert from RGB to CMYK to prepare a screen image for printing. Within color spaces, you can convert pixel data from one profile to another to display or print it on a different device. For example, you might convert between two CMYK profiles to prepare an image intended for printing in Japan for printing on US presses. You can work with color profiles directly, or indirectly while performing certain other image operations. ADS provides a default built-in sRGB profile. You can provide and refer to a color profile specified in an ICC file (which could have the .icc or .icm extension), or use a profile embedded in an image file.
Manipulating Color Profiles Directly The convertProfile command converts the pixel data in an image from one profile to another, so that the colors will appear correctly when displayed using the new profile’s device. You can convert colors within and between color spaces. You can, for example, convert colors between two RGB profiles, or between an RGB profile and a CMYK profile. In order to convert colors correctly, the command must know what profile the original data used, so it can determine what the corresponding color data is in the new profile. The original color profile (that is, the profile for the device that created the image, such as a digital camera) could be embedded in the image. If an image has an embedded profile, the convertProfile command converts from that profile to the new one. If it does not, the command converts from a default profile. Before converting the color data, you can replace the currently embedded profile or add an embedded profile using the assignProfile command. This command does not change the pixel information in any way; it just makes sure that the profile for the current pixel data is associated with the image. You can only assign a new color profile within the same color space as the existing profile; you cannot assign a CMYK profile to an image whose current profile is RGB, or the reverse. An embedded color profile can significantly increase the size of a saved file. For the JPEG format, you can set an attribute (embedICCProfile) in the optimization settings to choose whether an embedded profile should be saved with the file by the saveOptimized command. For more information on optimization settings, see “Saving Optimized Files” on page 112 and the Adobe Document Server XML Grammars Reference.
Adobe Document Server Developers Guide Dec 19, 2003 99 Basic Image Manipulations Manipulating Color Profiles Directly 5 Working with Color
Rendering Intents Converting images to a different color space often involves an adjustment of the colors to accommodate the gamut of the destination color space. Different translation methods use different rules to determine how the source colors are adjusted. For example, colors that fall inside the destination gamut may remain unchanged, or they may be adjusted to preserve the original range of visual relationships as translated to a smaller destination gamut. These translation methods are known as rendering intents because each technique is tuned for a different intended use of color graphics. The result of choosing a rendering intent depends on the graphical content of documents and on the profiles used to specify color spaces. Some profiles produce identical results for different rendering intents. The available rendering intents are: ● perceptual: Tries to preserve the visual relationship between colors in a way that is perceived as natural to the human eye, although the color values themselves may change. This is the same as the Image intent in Adobe PageMaker and Illustrator. This option is suitable for photographic, continuous tone images. ● saturation: Tries to create vivid color at the expense of accurate color. It scales the source gamut to the destination gamut, but preserves relative saturation instead of hue, so that when scaling to a smaller gamut, hues may shift. This is the same as the Graphics intent in Adobe PageMaker and Illustrator. This option is suitable for business graphics and charts, where the exact relationship between colors is not as important as having bright saturated colors. ● absoluteColorimetric: Tries to maintain color accuracy at the expense of preserving relationships between colors. Leaves colors that fall inside the destination gamut unchanged. When translating to a smaller gamut, two colors that are distinct in the source space may be mapped to the same color in the destination space. This option can be more accurate if the color profile of the image contains correct white point (extreme highlight) information. ● relativeColorimetric (default): The same as absoluteColorimetric, except that it compares the white point of the source color space to that of the destination color space and shifts all colors accordingly. Although the perceptual rendering intent has traditionally been the most common choice for photographic imagery, relativeColorimetric (which is the default method) can be a better choice for preserving color relationships without sacrificing color accuracy. For details of the convertProfile command, see the Adobe Document Server Command Reference.
100 Dec 19, 2003 Adobe Document Server Developers Guide Color Profiles in Other Operations Basic Image Manipulations Working with Color 5
EXAMPLE 5.10 Converting image data to a color profile This sample loads a PSD image, assigns the system-default profile, sRGB, to it, then converts the colors from the newly embedded profile to the USWebCoatedSWOP CMYK profile. It uses the perceptual rendering intent, which tries to preserve the relationships between colors.
Color Profiles in Other Operations Color conversion can take place when you are creating new Raster content by converting it from another format, or when you are importing new image data into existing Raster content. Color Conversion During Format Conversion Although the document formats support multiple color spaces, the Raster format supports only a single color space for an image. When you convert content from one of the document formats (PDF or PostScript) to the Raster image format, ADS rasterizes the document—that is, it displays the document (including any embedded images or vector elements) as if to a high- resolution screen, and captures the resulting image information. If there are multiple color spaces in document images, they are converted to a destination color space using a specified profile. The conversion commands convertPDFTORaster and convertPSToRaster have optional attributes that allow you to specify: ● The color space or profile of the new Raster content. If you specify a profile, the command converts colors to the profile’s color space, using that profile. If you specify the RGB or CMYK color space, it converts to the uncalibrated color space. ● The color translation method for colors that outside the gamut of the color profile, or rendering intent. These are the same as those defined for the convertProfile command. For details of these conversion commands, see the Adobe Document Server Command Reference. Color Conversion During Pixel Replacement When you use the replacePixels command to modify image data, you can provide the optional colorConversionRule attribute to specify how to convert the imported image to a color profile. The value of this attribute can be: ● alwaysConvert (the default): Converts all source pixels to the color profile of the target layer’s image, using the relativeColorimetric rendering intent. ● limitConversion: Ignores the color profiles in cases where the color space of the source and target are the same. For example, if the source pixels and the target layer’s image are
Adobe Document Server Developers Guide Dec 19, 2003 101 Basic Image Manipulations Color Space Support in ADS 5 Working with Color
both in the RGB color space, the command copies them without color conversion. However, if the source is in one color space, and the target in the other, the command uses the color profiles for conversion. For more control over the color conversion process, you can use the limitConversion rule with replacePixels, then use convertProfile to explicitly convert the colors in the resulting image. For details of the replacePixels command, see the Adobe Document Server Command Reference.
Color Space Support in ADS The following table shows how ADS reads and converts color spaces when image files are loaded from different formats.
TABLE 5.1 Color space support for image formats
Format Supported color spaces PSD 8-bit RGB 16-bit RGB (converted to 8-bit on load) 8-bit CMYK 16-bit CMYK (converted to 8-bit on load) 8-bit Grayscale (converted to RGB on load) 16-bit Grayscale (converted to 8-bit RGB on load) TIFF 8-bit RGB 16-bit RGB (converted to 8-bit on load) 8-bit CMYK 16-bit CMYK (converted to 8-bit on load) 8-bit Grayscale (converted to RGB on load) 16-bit Grayscale (converted to 8-bit RGB on load) ADS does not support alpha channels for TIFF. GIF 8-bit RGB 16-bit RGB (converted to 8-bit on load) JPEG 8-bit RGB 16-bit RGB (converted to 8-bit on load) 8-bit CMYK (converted to RGB on load) Grayscale (converted to RGB on load) PNG 8-bit RGB 16-bit RGB (converted to 8-bit on load) PDF, PostScript, EPS When converting to Raster, ADS preserves RGB and CMYK, and converts Grayscale to RGB. See “Color Conversion During Format Conversion” on page 101.
102 Dec 19, 2003 Adobe Document Server Developers Guide Changing Image Orientation Basic Image Manipulations Modifying Image Data 5
TABLE 5.1 Color space support for image formats (Continued)
Format Supported color spaces SVG referenced When converting SVG to PDF, ADS does not perform any color images transformation on referenced JPEG images, but embeds them byte-for-byte in the PDF content. Other referenced image formats are converted to Raster (as on load) before being embedded in the PDF.
Modifying Image Data
ADS provides commands for performing simple image manipulations such as rotation, and allows you to perform more comprehensive modifications by completely replacing a pixel or text layer.
Changing Image Orientation The ADS flip and rotate commands are equivalent to their Photoshop and ImageReady counterparts. ● The rotate command rotates an image by any number of degrees or radians, clockwise or counterclockwise. ● The flip command flips an image upside-down or reverses it from left to right. These commands affect an entire image canvas. You cannot rotate or flip individual layers or parts of layers.
EXAMPLE 5.11 Rotating an image This example saves three versions of the original image, rotated by 90 degrees, 45 degrees, and 60 degrees clockwise. Notice that when the image is rotated by anything other than a multiple of 90 degrees, the command must expand the canvas. When it does this, added pixels are opaque white, or transparent if there is no background layer.
Adobe Document Server Developers Guide Dec 19, 2003 103 Basic Image Manipulations Replacing All or Part of an Image 5 Modifying Image Data
The following figure shows the image rotation results:
Replacing All or Part of an Image You can import new image data into a pixel layer of Raster content using the replacePixels command. You might use this command, for example, to insert a product shot into a complicated template that contains drop shadows, overlaid text, and so on. The new pixel data can come from any supported image format (PSD, TIFF, GIF, JPEG, PNG) or from SVG content. If you import an SVG image into Raster content, the SVG content is converted to the Raster format before its pixels are inserted into the target layer in the Raster content. When the command writes the source pixels into the target layer or image, it places them, by default, such that the new image is centered in the target. You can change the position by specifying either or both of the valign and halign attributes such that the new image is aligned with the top, bottom, left, or right of the target layer or image. By default, the command maintains the aspect ratio when it resizes the image (constrainProportions="true"), but you can choose to allow resizing that changes the aspect ratio. When the command copies the source image, you can specify a scaling policy that controls whether the new image data is allowed to shrink or expand to fit the new canvas area. For details of the available policies, see “Scaling Policies” on page 92. An additional policy, doNotScale, is available for the replacePixels command. This prevents the command from either enlarging or shrinking the source image when copying it to the target layer. If the source image is too large for the target, the image is truncated. Finally, you can specify a color conversion rule for when to convert the pixel information in the source image to the color profile of the target image. By default, the command converts all source pixels to the color profile of the target layer’s image, using relativeColorimetric conversion (see “Working with Color” on page 99). You can choose to limit conversion (colorConversionRule="limitConversion") such that the command ignores the color profiles in cases where the color space of the source and target are the same. For example, if the source pixels and the target layer’s image are both in the RGB color space, the command copies them without color conversion. However, if the source is in CMYK, and the target in RGB, the command uses the color profiles for conversion. For more information, see “Color Conversion During Pixel Replacement” on page 101.
104 Dec 19, 2003 Adobe Document Server Developers Guide Replacing All or Part of an Image Basic Image Manipulations Modifying Image Data 5
EXAMPLE 5.12 Replacing pixels to add a product shot to an image This example loads and stores a PSD file containing an image of a guitar (a product shot), and another containing a product image template. It uses the replacePixels command to replace the layer named Product in the product_image file with the guitar image, allowing the command to scale the image freely to the target layer size while maintaining the aspect ratio.
EXAMPLE 5.13 Duplicating one pixel layer out of several layers This example loads a PSD file and hides all layers except one. In the output content named layerToCopy, only the bottommost layer is visible. It adds a new layer immediately above the visible layer, and uses the replacePixels command to copy the image from the one visible layer in the saved content to the new layer.
EXAMPLE 5.14 Applying a layer effect by replacing pixels This example applies the drop-shadow layer effect to an image by copying the image pixels into a template layer that has that effect applied. The example loads an image of a baseball, and retrieves the image information, so that it can use reference(adobe-content) to access the height and width. It then loads a small template with appropriate drop-shadow parameters, and uses the stored image information to enlarge the template to be the same size as the baseball image. It further enlarges the template by 30 pixels to make sure there is room for the drop shadow.
Adobe Document Server Developers Guide Dec 19, 2003 105 Basic Image Manipulations Replacing Text in an Image 5 Modifying Image Data
The replacePixels command replaces the pixels in the newly enlarged template layer with the baseball image pixels, and the trim command trims off any excess pixels from the edges of the canvas. Finally, the example saves the image with the drop shadow to a new PSD file.
Replacing Text in an Image You can replace or modify text in an image in several ways: ● Use the replaceText command to replace specific text in a specific PSD text layer. ● Use the ADS variable replacement mechanism: – With a text variable you have defined and bound in Illustrator or ImageReady. – With the ADS-defined variable defaultTextVariable to replace the topmost text layer in any PSD image. For more information and examples, see Chapter 7, “Replacing Variables in SVG and PSD Files.” ● Use the set command to replace or modify the textFlow element in Raster content, or the flowDef element in SVG content. See “Setting Text Characteristics” on page 127.
106 Dec 19, 2003 Adobe Document Server Developers Guide Changing Colors in an Image Basic Image Manipulations Modifying Image Data 5
For more information on the text representation and examples of text replacement methods, see Chapter 6, “Changing Text in Images,” and t h e Adobe Document Server XML Grammars Reference. For text replacements, make sure the required fonts are available to the ADS server. If they are not, ADS uses a default font. For further information about fonts, see the ADS Installation and Configuration Guide.
Changing Colors in an Image You can use the set command to change color attributes of text, such as the fill or stroke color (see Chapter 6, “Changing Text in Images”). If you have defined a color-overlay style for a text or pixel layer in Photoshop, you can replace it using the set command, with the target /psd/layer[n]/style/colorOverlay. Setting a color overlay is useful for dynamically changing a color feature such as a car body or piece of clothing in a catalog. In the colorOverlay element, the color attribute specifies a color as a hexadecimal color value from #000000 to #FFFFFF. The default color is #FF0000, or red. In addition to the new color, attributes control the opacity of the color, which is in the range 0.0 to 1.0 (1.0, the default, means completely opaque), and the blendMode. The blend mode controls how the new color is blended with the original color. The default is to completely replace the old color (normal), but you can choose from many blend modes that allow you to achieve special effects, such as hardlight or softlight, darken or lighten, and so on. For a complete description of the blend modes, see the Adobe Document Server XML Grammars Reference.
EXAMPLE 5.15 Replacing a color overlay in an image layer This example replaces the logo color in an image of a stoplight, which has been specified in a color overlay. It shows the "Caution" layer, hides the "Go" and "Stop" layers, and saves the result to a new PSD file.
Adobe Document Server Developers Guide Dec 19, 2003 107 Basic Image Manipulations Controlling Visual Quality 5 Modifying Image Data
Controlling Visual Quality You can use commands to adjust the contrast or level of an image in RGB Raster content. These commands have the same effect on the image as the similar commands you can apply interactively through the Photoshop and ImageReady menus. The autoContrast and autoLevels commands both use a similar technique to adjust either the contrast or the level of an image. ● Contrast adjustment can improve the appearance of many photographic or continuous-tone images. It does not improve flat-color images. It improves image appearance by making the highlights appear lighter, and the shadows appear darker. ● Level adjustment gives good results for an image with an average distribution of pixel values or for an image with an overall color cast. These commands work on one layer at a time. If the image is not in a single layer, and if you want to adjust multiple layers in a single pass, you must first flatten the image using the flatten command. For more information on these concepts and operations, see the Photoshop documentation.
EXAMPLE 5.16 Automatically adjusting contrast in an image This sample loads an image, flattens the layers so that the entire image can be adjusted, and uses the autoContrast command to automatically adjust the contrast. The sample saves an optimized file; if there are no optimization settings in the original PSD file, the result is a 256-color GIF file.
108 Dec 19, 2003 Adobe Document Server Developers Guide Retrieving Image Information Basic Image Manipulations Accessing Raster Content 5
Accessing Raster Content
The internal Raster format, like the PSD format, is binary. However, ADS defines an XML content, similar to a subset of SVG, that is used to show certain image information in XML, and also provides access to certain features through the set command.
Retrieving Image Information You can use the imageInfo command to retrieve information from Raster content. The information is shown in XML that reflects the Raster content model. The imageInfo result shows default values for any elements that have not been explicitly set to something other than the default (unlike SVG, for example, where elements that have no explicit values are not visible in the file). The imageInfo result is stored as XML content. You can access elements in that XML content using the reference(adobe-content) syntax, as shown in “Applying a layer effect by replacing pixels” on page 105. The command returns the same kind of image information for all Raster content, regardless of the file format from which it was loaded or converted. However, some of the content model elements represent PSD features (layers and layer sets) that are only minimally present in files loaded from other formats. For more information, see “Layers in Images from Other Formats” on page 98. The following sample of Raster content information, as retrieved with the imageInfo command, shows some of the hierarchy of elements and illustrates attribute settings:
Adobe Document Server Developers Guide Dec 19, 2003 109 Basic Image Manipulations Setting Elements of an Image 5 Accessing Raster Content
Setting Elements of an Image You can use the set command to replace or modify certain elements and attributes in Raster content, using an abbreviated XPath syntax to reference the elements and attributes that you want to change. Not all features that you can see using the imageInfo command can be set using the set command. You can set or replace the following properties:
Target for set command Description
/psd/@copyright A copyright message for the content.
/psd/layerSet[n]/@visibility Layer set properties. /psd/layerSet[n]/@opacity
/psd/layerSet[n]/layer[n]/@visibility Layer color and appearance properties, /psd/layerSet[n]/layer[n]/@opacity where layer is in a layer set. /psd/layerSet[n]/layer[n]/style/colorOverlay
/psd/layer[n]/@visibility Layer color and appearance properties, /psd/layer[n]/@opacity where layer is not in a layer set. /psd/layer[n]/style/colorOverlay
/psd[/layerSet[n]]/layer[n]/textFlow Text layer properties. .../flow/p/span (contains text) There are many text attributes you can set .../region/path within a span. .../fonts/font
/psd/optimizationSettings Preferred optimization format and .../GIFFormat properties. .../PNG8Format There are many attributes you can set for .../PNG24Format each format, with different attributes .../WBMPFormat applicable to different formats. .../JPEGFormat
/psd/fileInfo IPTC metadata properties. .../property
110 Dec 19, 2003 Adobe Document Server Developers Guide Setting Elements of an Image Basic Image Manipulations Accessing Raster Content 5
The following figure shows the Raster target hierarchy.
/psd @copyright
/fileInfo /layerSet /optimizationSettings @visibility @opacity
/GIFFormat /PNG8Format /PNG24Format /WBMPFormat /JPEGFormat (many attributes) /layer @visibility @opacity /style /textFlow
/colorOverlay /flow /region /fonts @enabled @color /p /path /font @opacity @blendMode /span (many attributes)
Typically, you will use the set command to adjust features such as the opacity and visibility of layers and layer sets (see “Layer Manipulations” on page 95), and to set the optimization parameters that control how the saveOptimized command saves the content (see “Saving Content” on page 59, “Saving Optimized Files” on page 112, and the Adobe Document Server XML Grammars Reference). You can also use the set command to replace text characteristics and text color overlays. See “Setting Text Characteristics” on page 127.
EXAMPLE 5.17 Using the set command to change copyright information for an image This example uses the set command to set the copyright message for a PSD file, which is referenced as an attribute of the root psd element in the Raster content model.
EXAMPLE 5.18 Copying a value from one Raster content holder to another This example sets the third layer of the current content to the same opacity as the yellow layer of the image in the content named guitar.
Adobe Document Server Developers Guide Dec 19, 2003 111 Basic Image Manipulations Tuning Optimization Settings Outside ADS 5 Treating PostScript and PDF Content as Images
For More information ● The Raster content model and XPath support are described in detail in the Adobe Document Server XML Grammars Reference. ● The set and imageInfo commands are described in detail in the Adobe Document Server Command Reference.
Treating PostScript and PDF Content as Images
You may want to treat a document as an image, because, for example, the document contains only an image, or to convert it for display by an application that does not handle PostScript or PDF. In ADS, you can convert PostScript content to Raster content using the convertPSToRaster command, and PDF content to Raster content using the convertPDFToRaster command. You can convert Photoshop EPS to Raster, but Photoshop-specific information stored in embedded image resources is not retained. Once the information is in Raster content, you can set the optimization parameters, for example, and save it to an optimized format. If you want to store an image as a document, you can convert Raster content to PostScript or to PDF content, using the convertRasterToEPS and convertRasterToPDF commands. The PostScript generated by these commands is Photoshop-compatible EPS. For information on how ADS translates colors in a document when converting them to an image format, see “Color Conversion During Format Conversion” on page 101.
Saving Optimized Files
You can use the saveOptimized command to save Raster or SVG content to one of the optimized files formats GIF, JPEG, PNG, or WBMP. The format, along with other optimization parameters, is controlled by the content’s optimization settings. If you used Save for Web in Photoshop or Illustrator, then loaded the file into ADS, ADS maintains the optimization settings that you specified. You can also create or modify optimization settings in ADS by using the set command to set the optimizationSettings element in Raster or SVG content. For detailed information on optimization settings in Raster content and Save-for-Web settings in SVG content, see the Adobe Document Server XML Grammars Reference.
Tuning Optimization Settings Outside ADS The Save for Web feature of Adobe Photoshop and Adobe Illustrator allows you to fine tune the Web compression settings for a particular image when you create it, and to save those settings with the PSD or SVG file. When you create a variation of the image, by changing the size or text, for example, you can automatically reuse the original compression settings. Having the original artist optimize the Web compression settings for each image is especially
112 Dec 19, 2003 Adobe Document Server Developers Guide Tuning Optimization Settings in ADS Basic Image Manipulations Saving Optimized Files 5
important if you will use ADS to create the variations automatically. You can maintain the original artistic intent over hundreds of reuses. Photoshop 5.5 (July 1999) and Illustrator 9.0 (April 2000) first implemented the Adobe "Save for Web" feature, so some of your legacy files may already have taken advantage of "Save for Web". Your current workflow should include the Save for Web step so that you can realize future benefits. To tune optimization settings for a PSD file in Photoshop, or for an SVG file in Illustrator, use the following general procedure: 1. Create or load the image. 2. From the File menu, choose Save for Web. 3. Decide if the image should be a GIF, JPEG, or PNG. 4. Determine the best compression settings for this particular image. 5. Click OK. This saves a Web-ready copy of the image based on your settings. If you loaded this file into ADS, it would not retain the optimization settings. 6. Save the image as a PSD file (from Photoshop) or an SVG file (from Illustrator). In Illustrator, you must check Include Slicing Data in the Advanced section of the Save as SVG dialog box in order to save the optimization settings with the file. The resulting PSD or SVG file has your compression settings embedded in it. Use this file with ADS, not the file created in step 5.
NOTE: Both the .ai and SVG formats can store your compression settings, but ADS can only work with SVG files. You may want to save both .ai and SVG versions of your files. For full details of saving and tuning in these applications, see the Photoshop and Illustrator documentation.
Tuning Optimization Settings in ADS You can use the set command to create or modify optimization settings in Raster or SVG content. You can address a particular optimization attribute to set its value, or replace all or part of the optimizationSettings element.
EXAMPLE 5.19 Setting an optimization attribute This example uses abbreviated XPath syntax to make the existing attribute the direct target of the set command. This example does not change any other attributes that were already set in the original file.
Adobe Document Server Developers Guide Dec 19, 2003 113 Basic Image Manipulations Tuning Optimization Settings in ADS 5 Saving Optimized Files
This example addresses the existing format element directly as the target, and replaces it with a new format element containing a quality attribute value. All other JPEG attributes are allowed to default, regardless of whether they were specified in the original file.
EXAMPLE 5.20 Changing the preferred optimization format with set This example loads a PSD file, then replaces all existing optimization settings in that file. The set command replaces the entire target element,
EXAMPLE 5.21 Choosing an optimization format automatically This example loads a PSD image, determines whether GIF or JPEG optimization should be applied to the image, adjusts the optimization settings to produce a file size of no more than 30K, and saves the content in the optimized format.
114 Dec 19, 2003 Adobe Document Server Developers Guide Balancing Quality and Size in Optimized Image Files Basic Image Manipulations Saving Optimized Files 5
Balancing Quality and Size in Optimized Image Files When you save image content to an optimized file format, certain optimization settings control the quality of the resulting image. In general, you can choose to preserve quality at the expense of a larger file size, or reduce the file size by sacrificing image quality. See also “Changing the Image File Size” on page 115. ● For the GIF file format, set the lossy attribute to a value from 0 to 100. A lower value results in an image of higher quality with a larger file size. ● For both GIF and PNG8 formats, if the image contains a fixed color table, you can set the autoReduce attribute to true to remove infrequently-used colors from the table, resulting in a smaller file. In addition, you can specify a reductionAlgorithm to be used to decrease file size. ● For the JPEG file format, set the quality attribute to a value from 0 to 100. A higher value results in an image of higher quality with a larger file size. In addition, you can set the optimized attribute to true to create an enhanced JPEG with a slightly smaller file size. Adjusting the blurAmount can affect the file size. Embedding a color profile (embedICCProfile) or metadata (embedMetadata) increases file size. For more information on optimization settings, see the Adobe Document Server XML Grammars Reference.
EXAMPLE 5.22 Adjusting the quality of an optimized file This example loads a PSD file, then replaces all existing optimization settings in that file with a new set. The set command replaces the entire target element,
Changing the Image File Size The optimizeToSize command adjusts optimization settings in an RGB image so that when you save it with the saveOptimized command, the file will be no larger than the file size you specify. This ADS command is similar to the Optimize to File Size command in Photoshop. It reduces the file size at the expense of image quality. (This command does not work for CMYK images.)
Adobe Document Server Developers Guide Dec 19, 2003 115 Basic Image Manipulations Saving Metadata with Optimized Files 5 Saving Optimized Files
The command allows you to quickly achieve a desired file size without having to test different optimization settings. It adjusts the optimal number of colors for GIF or PNG8 format or the optimal color quality for JPEG format that will result in a file below the size that you specify. You can choose to let the command determine whether GIF or JPEG is a more optimal format for the image, and then adjust the optimization settings accordingly. The command selects JPEG for any image that appears to be a photograph and does not use transparency. It selects GIF for all other images. If you choose not to select the output format automatically, the command retains the image’s current optimization settings. The command can tune parameters for the JPEG, GIF, and PNG8 formats. The PNG24 or WBMP formats do not have tunable parameters, so if one of those was the original preferred format, the command reports an error. You must use the set command or a tool outside ADS to select another format (PNG or WBMP) for the optimized file, or to adjust other optimization settings individually. For more information on optimization, see “Saving Content” on page 59, “Saving Optimized Files” on page 112, and the chapter “Accessing Raster Content” in the Adobe Document Server XML Grammars Reference.
EXAMPLE 5.23 Creating a smaller image file This example loads a PSD image, determines whether GIF or JPEG optimization should be applied to the image, adjusts the optimization settings to produce a file size of no more than 30K, and saves the content in the optimized format.
Saving Metadata with Optimized Files In the saveOptimized command, you can use the optional metadata attribute to specify whether to save metadata with an optimized image file, and what metadata formats to save (XMP, EXIF, and/or IPTC). If you do not supply the attribute, no metadata is saved with the file. You can specify any combination of the supported formats; however, the non-XMP formats apply only to JPEG files. If the file is not being written in JPEG format, those values are ignored. ● You can include XMP format metadata for any output file. ● You can specify any combination of XMP, EXIF, or IPTC metadata to be saved with a JPEG file. Upon save, metadata in all formats is guaranteed to be consistent. For more information on metadata formats, see Chapter 4, “Working with File Metadata.” The JPEG optimization settings also contain an attribute, embedMetadata, that you can use to specify IPTC metadata. If you specify this attribute (using the set command), the IPTC
116 Dec 19, 2003 Adobe Document Server Developers Guide Custom Color Palettes in Optimized Files Basic Image Manipulations Saving Optimized Files 5
metadata is included in the saved JPEG file, regardless of the metadata value in the saveOptimized command. For more information on this and other optimization settings, see the chapter “Accessing Raster Content” in the Adobe Document Server XML Grammars Reference.
Custom Color Palettes in Optimized Files You can use custom color palettes with GIF and PNG8 images. You cannot programmatically create a custom color palette within ADS, but ADS loads and preserves custom color palettes previously defined in Photoshop or ImageReady. Each time you use the saveOptimized command to save an image as a GIF or PNG8 in ADS, the Selective, Adaptive, or Perceptual color reduction algorithm creates a new color palette by analyzing the colors present in the image. If you plan to use the same colors for all images (for example, if you are just changing text), you can switch the image to a custom palette in ImageReady. To use a custom palette, use the Selective, Adaptive, or Perceptual algorithm in Save for Web in Photoshop, or the Optimize palette in ImageReady. Select Custom as the Color Reduction Algorithm setting. This “freezes” the current color palette, and allows ADS to skip the color analysis and palette creation steps each time it saves the file, which saves processing time. When you use a custom color palette, only colors contained in the palette are used in the optimized image file. Therefore, if you add pixel data to the file in ADS (for example, if you add a logo to a graphic) you may get unexpected color shifts in the new pixel data.
Saving Dynamic PSD and Animated GIFs ADS does not allow you to manipulate slices, rollovers, image maps, and animations. ADS ignores slicing, rollovers, and image maps when you save Raster content. ADS maintains the animation frames when you load animated PSD files. If you load animated GIFS into ADS, it transforms the GIF animation frames into PSD animation frames. You can save Raster content containing animation frames to produce an animated GIF or PSD result.
Adobe Document Server Developers Guide Dec 19, 2003 117 Basic Image Manipulations Saving Dynamic PSD and Animated GIFs 5 Legacy File Limitations
Legacy File Limitations
Legacy PSD and SVG files that originate in older versions of Adobe Photoshop, ImageReady, Illustrator, and GoLive® may not support features that ADS uses, if those features were not available in the application that created the file. The following tables summarize when key features were introduced in the various applications.
TABLE 5.2 Photoshop feature introductions
Feature 3.0 5.0 5.5 6.0 Copyright Notice X Layer Names X Unicode Layer Names X Editable Text Layers X Layer Effect Color Overlay X Optimization Settings X Layer Sets X
.
TABLE 5.3 ImageReady feature introductions
Feature 1.0 2.0 3.0 7.0 Optimization Settings X Replacement Variables X
.
TABLE 5.4 Illustrator feature introductions
Feature 9.0 10.0 Graphing X .ai format changes from EPS to PDFa X SVG file format X Flow Text X Replacement Variables X
a. ADS can load .ai files from version 7.0 and up.
.
TABLE 5.5 GoLive feature introductions
Feature 5.0 6.0 Replacement Variables X Dynamic Link Palette X
118 Dec 19, 2003 Adobe Document Server Developers Guide 6 Changing Text in Images
This chapter describes how to set, replace, or modify text in Raster or SVG content. You can modify the text itself, using several different techniques, or use the set command to modify text display characteristics, such as the font and color. This chapter contains the following sections:
Changing Text in Images starting on page 119 Changing Text Attributes in Text Flows starting on page 123
Changing Text in Images
Text is stored in text layers in PSD files, and in text flows (the flowDef element) in SVG files. ADS provides several ways to replace or modify text in a PSD or SVG file, automatically or explicitly:
Use the replaceText command to replace See “Replacing Text in Raster Content” on specific text in a specific text layer of a PSD file. page 120 and the Adobe Document Server Command Reference.
Use automatic variable replacement with a See “Replacing Text Variables in PSD Files” on text-type variable that you define in ImageReady page 120 and “Replacing Text Variables in or Illustrator to replace all text in an SVG text SVG Files” on page 122. object or a PSD text layer.
Use automatic variable replacement with the See “Replacing Text Variables in PSD Files” on ADS-defined variable defaultTextVariable to page 120. replace the topmost text layer in any PSD file.
Use the set command to replace or modify the See “Changing Text Attributes in Text Flows” textFlow element in Raster content, or change on page 123. the color of text by modifying the colorOverlay element.
Use the set command to replace or modify the See “Changing Text Attributes in Text Flows” flowDef element in SVG content. on page 123.
For more information on these techniques and formats, see also the Adobe Document Server Command Reference, the chapter “Accessing Raster Content” in the Adobe Document Server XML Grammars Reference, and the SVG specification at the following URL: http://www.w3.org/TR/SVG/paths.html
Adobe Document Server Developers Guide Dec 19, 2003 119 Changing Text in Images Replacing Text in Raster Content 6 Changing Text in Images
For text replacements, make sure the required fonts are available to the ADS server. If they are not, ADS uses a default font. For further information about fonts, see the ADS Installation and Configuration Guide.
Replacing Text in Raster Content In Raster content, replaceable text is always in a text layer. (Bitmapped text in a pixel layer is not replaceable as text, although you can replace the image with another image containing different bitmapped text.) You can use the replaceText command to replace all of the text in a text layer, or to replace a specific string with another string.
EXAMPLE 6.1 Replacing all text in a layer This example replaces all of the text in the layer named Title with the replacement text The National Pastime, and all of the text in the layer named Description with the replacement text 1997 National League Championship Series.
EXAMPLE 6.2 Replacing specific text in a layer This example replaces the text string 69.99 in the layer named Base Price with the text 400, and the text string 50 in the layer named Percentage with the text 40.
120 Dec 19, 2003 Adobe Document Server Developers Guide Replacing Text in an SVG Text Flow Changing Text in Images Changing Text in Images 6
For any PSD file with one or more text layers, ADS automatically defines a text-type variable named defaultTextVariable and binds it to the topmost text layer (that is, the one with the highest index number). To replace the text in the topmost text layer automatically or explicitly, specify the new text value for the default variable named defaultTextVariable in the XML replacement data:
EXAMPLE 6.3 Replacing the automatic text variable value The following example performs an explicit variable replacement, using XML replacement data that it loads inline in the loadContent command. It replaces the text in the topmost layer of the PSD file imageWithCaption with the string “Clearance!”
Replacing Text in an SVG Text Flow You can use the set command to replace the flowDef element or one of its subelements in SVG content. Depending on how you specify the target, you can replace just the text, or the text and its attributes, such as the font or style. See “Changing Text Attributes in Text Flows” on page 123. The following is an example of a text flow in an SVG file: product name
Adobe Document Server Developers Guide Dec 19, 2003 121 Changing Text in Images Replacing Text in an SVG Text Flow 6 Changing Text in Images
EXAMPLE 6.4 Replacing text in an SVG text flow This example uses the set command to replace the text in the sample SVG text flow.
EXAMPLE 6.5 Replacing an entire text flow in SVG content This example uses the set command to replace the whole flow, both text and attributes, for the same SVG sample. My Product
122 Dec 19, 2003 Adobe Document Server Developers Guide The Structure of a Text Flow Changing Text in Images Changing Text Attributes in Text Flows 6
● If the replacement data value is a p element, ADS replaces all the child elements of the flow element with the new p element. ● If the replacement data value is a span element, ADS replaces all the child elements of the first p element of the flow element with the new span element. For details of how to specify replacement values for text variables and how to apply replacement values, see Chapter 7, “Replacing Variables in SVG and PSD Files.”
Changing Text Attributes in Text Flows
This section explains the XML structure of text flows in PSD and SVG files. Understanding this structure allows you to change the text in text flows in SVG and Raster content using the set command. By setting elements and attributes of a text flow, you can affect the style and appearance of text, as well as the actual text. When you replace simple text bound to a text variable or use the replaceText command, you change only the text itself; the style is not affected.
The Structure of a Text Flow A text flow is represented by a hierarchy of elements. A text flow hierarchy is defined by the SVG specification. For complete information, see the SVG specification at http://www.w3.org/TR/SVG/paths.html. ADS defines a similar hierarchy for Raster content, extended for PSD text information. Figure 6.1 shows the hierarchical structure of the elements in a text flow, and specifies which elements apply to Raster and to SVG content.
FIGURE 6.1 XML structure of text flows in Raster and SVG content
Raster structure SVG structure
1 or more 1 or more order is significant order is significant
w w h h h h 1 or more 1 or more order is significant order is significant label label label label w w w w h h h h Adobe Document Server Developers Guide Dec 19, 2003 123 Changing Text in Images The Structure of a Text Flow 6 Changing Text Attributes in Text Flows As you can see from this figure, the element hierarchies for PSD and SVG text flows are very similar; they differ only in the name of the top element and the absence of the font elements in the SVG case. The fonts element can optionally provide a more reliable way of locating fonts for PSD files. The actual text content of a text flow is specified in the flow element or its subelements. The other elements provide attributes, but no content. The region and path elements define a position or shape for the text. ADS supports two types of text in a text flow, area text and point text: ● Area text — The area for area text is defined by a rectangle, drawn according to instructions in the path element. Area text wraps within the defined rectangle. You create area text in Photoshop or Illustrator by clicking and dragging the cursor with the Text tool to create a rectangular area in a document and then typing text in that rectangle. Within a text area, the p elements correspond to paragraphs. The number of p elements are determined by how many Return characters the text contains. When entering area text, pressing the Return key creates a new paragraph. If you press the Return key twice, you have three paragraphs, each of which is represented by its own p element. ● Point text — The area for point text is defined by a single origin point expressed in the path element. Point text contains a single line of text that does not wrap. You create point text in Photoshop or Illustrator by clicking in a document with the Text tool and typing the text. The text flow for point text has only one p element. Each PSD text layer in a PSD file has one and only one text flow. If an image contains six text layers, there are six text flows in the image. SVG images do not have the notion of layers, but an SVG image can contain multiple text flows. Table 6.1 gives a brief summary of each of the elements in Figure 6.1. For complete details of these elements and their attributes, see the chapter “Accessing Raster Content” in the Adobe Document Server XML Grammars Reference. 124 Dec 19, 2003 Adobe Document Server Developers Guide The Structure of a Text Flow Changing Text in Images Changing Text Attributes in Text Flows 6 TABLE 6.1 Summary of elements and attributes in PSD and SVG text flows Element & description Attributes PSD SVG Adobe Document Server Developers Guide Dec 19, 2003 125 Changing Text in Images The Structure of a Text Flow 6 Changing Text Attributes in Text Flows TABLE 6.1 Summary of elements and attributes in PSD and SVG text flows (Continued) Element & description Attributes PSD SVG adobe-auto-leading-percent ✔✔ Required adobe-burasagari ✔✔ Defines a paragraph. Its attributes define the paragraph style. adobe-consecutive-hyphens ✔✔ Contains one or more span adobe-every-line-composer ✔✔ subelements that contain the actual adobe-hanging-roman ✔✔ text. Each paragraph contains a style-span for each style of text in the adobe-hyphenate-capitalized ✔✔ paragraph. adobe-hyphenate-word-size ✔✔ Can contain text. adobe-hyphenation-zone ✔✔ adobe-justification-glyph-scaling-desired ✔ adobe-justification-glyph-scaling-max ✔ adobe-justification-glyph-scaling-min ✔ adobe-justification-letter-spacing-desired ✔✔ adobe-justification-letter-spacing-max ✔✔ adobe-justification-letter-spacing-min ✔✔ adobe-justification-word-spacing-desired ✔✔ adobe-justification-word-spacing-max ✔✔ adobe-justification-word-spacing-min ✔✔ adobe-kinsoku-set ✔ adobe-leading-type ✔✔ (cont’d) adobe-mojikumi-set ✔ adobe-preferred-kinsoku-order ✔ end-indent ✔✔ hyphenate ✔✔ hyphenation-push-character-count ✔✔ hyphenation-remain-character-count ✔✔ space-after ✔✔ space-before ✔✔ start-indent ✔✔ text-align ✔✔ text-align-last ✔✔ text-indent ✔✔ All span attributes can be specified on this element. Values set in the span element override those set here. 126 Dec 19, 2003 Adobe Document Server Developers Guide Setting Text Characteristics Changing Text in Images Changing Text Attributes in Text Flows 6 TABLE 6.1 Summary of elements and attributes in PSD and SVG text flows (Continued) Element & description Attributes PSD SVG adobe-baseline-direction ✔ Required adobe-faux-bold ✔✔ The attributes define a character style that applies to the contained text. adobe-faux-italic ✔✔ Can contain text. adobe-font-baseline-option ✔✔ adobe-horizontal-scale ✔✔ adobe-ligatures ✔ adobe-no-break ✔✔ adobe-old-style-figures ✔ adobe-tsume ✔ adobe-vertical-scale ✔✔ adobe-y-underline ✔ baseline-shift ✔✔ fill ✔✔ font-family ✔✔ font-size ✔✔ font-variant ✔ kerning ✔✔ letter-spacing ✔✔ line-height ✔✔ (cont’d) stroke ✔ text-decoration ✔✔ text-transform ✔ Setting Text Characteristics You can use the set command to address individual attributes at any level of the text flow hierarchy, or to replace an entire element in the hierarchy, including both the attributes and text. For details of how to use the set command, see the Adobe Document Server Command Reference. Adobe Document Server Developers Guide Dec 19, 2003 127 Changing Text in Images Setting Text Characteristics 6 Changing Text Attributes in Text Flows EXAMPLE 6.6 Changing a font size This example loads a PSD file that contains a text layer named caption. It changes the font size in the first span of the text flow to 36 points. EXAMPLE 6.7 Changing the fill color for text This example sets the fill attribute to #FF0000 (red) at the level of the flow element. Although fill is actually an attribute of span, when you set it at the higher level, the value applies to any span subelements that do not define a different value for it. EXAMPLE 6.8 Changing the overlay color in a text layer This example loads a PSD file that contains a text layer named caption, for which the creator defined a color overlay style in Photoshop. It changes the color overlay for the entire text layer to yellow. 128 Dec 19, 2003 Adobe Document Server Developers Guide Setting Text Characteristics Changing Text in Images Changing Text Attributes in Text Flows 6 EXAMPLE 6.9 Replacing an entire text flow in Raster content This example loads a source PSD file with a text layer named caption, and replaces the entire textFlow element in that layer. The new text flow provides the text “Now 30% off!,” changing the font size so that “30%” is bigger than the rest of the text. Now 30% off! Adobe Document Server Developers Guide Dec 19, 2003 129 Changing Text in Images Setting Text Characteristics 6 Changing Text Attributes in Text Flows EXAMPLE 6.10 Replacing text flow attributes in SVG content This example uses the set command to replace both an entire flow and specific text flow elements for SVG content. Mr. Smart 100 Main Street City, ST 90000 130 Dec 19, 2003 Adobe Document Server Developers Guide Replacing Variables in SVG and PSD 7 Files This chapter describes the variable replacement facility in ADS. It contains the following sections: Overview of Variable Binding and Replacement starting on page 131 Automatic Variable Replacement starting on page 133 Replacing Variables Explicitly starting on page 134 Specifying Replacement Data starting on page 136 Overview of Variable Binding and Replacement Variables provide a convenient and portable way to replace elements of a file. You can define and replace variables in SVG and PSD source files. When you define variable bindings, you create a definition in the file that associates a variable name with a particular element in the file. You can bind a variable to a major element such as an entire text flow in a PSD file or the contents of a graph in an SVG file, or to a very specific feature such as the fill attribute of a circle in an image. To replace the element, all you need to know is the name of the variable. Variables give graphic designers the flexibility to make modifications to images without invalidating already existing code in ADS command sets. A designer can change the structure of a template file, and, as long as the variable names remain constant, there is no need to modify or update the associated ADS command set that uses that template. ADS provides a very flexible mechanism for automatic variable replacement in various circumstances, and also provides a command that you can use to explicitly replace variables at any point in the execution of a command set. To use the variable replacement facility in ADS, you must first create template SVG and PSD files. Use Adobe Illustrator 10 and Adobe ImageReady 7 (the Web-authoring application that ships with Photoshop 7) to define named variables and bind them to those portions of the file that you want to replace or fill with run-time data. You cannot create new variables or change their bindings with ADS. ● To create an SVG file that contains variable bindings, use the Variables palette in Adobe Illustrator. When you save the SVG file in Illustrator 10, you must export the variable bindings information by checking "Include Extended Syntax for Variable Data" in the "Save as SVG" dialog. Illustrator 10 can create SVG file variables of type visibility, graph, text, and image replacement. ADS can recognize and replace all of these variable types. Adobe Document Server Developers Guide Dec 19, 2003 131 Replacing Variables in SVG and PSD Files 7 Overview of Variable Binding and Replacement ● To create a PSD file that contains variable bindings using the Variables palette in ImageReady 7. ImageReady 7 can create PSD file variables of type visibility, text replacement, and image replacement. NOTE: In Adobe GoLive version 6.0, you can bind only text and visibility variable types. ADS can replace an element bound to a variable with new data that you supply in XML format. ADS can replace variables automatically when you load a file, or you can use the applyVariables command to replace variables explicitly in the course of executing a command set. To replace variables in a file, you load two separate source files into ADS: the replacement data, and the SVG or PSD file containing the variables. You can load either or both of the files as part of the ADS request (from the command line or API), a command file can load the files using the loadContent command, or you can combine these methods. You can also load the replacement data inline in the loadContent command. You can use the same replacement data for several source files, or replace variables in the same source file with several sets of data. The automatic variable replacement behavior depends on how the files are loaded and how the replacement data is named. You can do any of the following: ● Replace variables completely automatically, passing both source files in the request, without specifying a command set. ● Replace variables automatically, passing in both source files, then continue processing with a command set. ● Provide only the replacement data file with the request. ADS uses that data to replace variables automatically as commands load different source files containing variables. ● Load the replacement data using the loadContent command, giving it the special content name data. ADS uses that data to replace variables automatically as commands load different source files containing variables. ● Load and name both the data and variable source files using the loadContent command, and replace variables explicitly using the applyVariables command. 132 Dec 19, 2003 Adobe Document Server Developers Guide Replacing Variables in SVG and PSD Files Automatic Variable Replacement 7 Automatic Variable Replacement You can cause ADS to replace variables in an SVG or PSD file automatically (without an explicit command) in a number of ways. Automatic replacement depends on how and when you load the SVG or PSD source file containing variables and the XML file containing the replacement data. For ADS to perform automatic variable replacement, the replacement data must be loaded and named with the reserved name data, before the file containing the variables. You can load the XML variable replacement data in any of these ways: ● Use an explicit loadContent operation to load the file or inline data and name it data using the out attribute. ● On the command line, specify the data file in the -data option to the ADS command. ● When constructing a request with one of the ADS APIs, use the addVariable method to add each variable name and replacement value to the request. ADS collects all of the values into an XML content holder called “data” before executing the command set. You can pass in or load the data and source files in any combination. ADS automatically replaces variables in an SVG or PSD file whenever there is an XML content holder named data available. This happens in any of the following circumstances: ● You pass in both an SVG or PSD source file (using the -source option) and XML replacement data (using the -data option) on the command line. If you also specify a command set, ADS performs the variable replacement before executing any of the commands. If you do not specify a command set, ADS performs the replacement and saves the updated file with the name Untitled. ● You pass in XML replacement data on the command line or with the request, then in the command set use the loadContent command to load an SVG or PSD file. The variable replacement is performed immediately after the file containing the variables is loaded. The variable data is accessible from ADS as XML content named data, and will be used to replace variables for any subsequently loaded SVG or PSD files as well. ● In the command set, you load an XML data file (or inline data) containing the replacement values using the loadContent command, name it data using the out attribute, then use the loadContent command to load an SVG or PSD file. The variable replacement is performed immediately after the file containing the variables is loaded. The XML content named data will be used to replace variables for any subsequently loaded SVG or PSD files as well. If there is no XML content named data when an SVG or PSD file is loaded, automatic variable replacement does not occur and any original variable values remain unchanged. Adobe Document Server Developers Guide Dec 19, 2003 133 Replacing Variables in SVG and PSD Files 7 Replacing Variables Explicitly EXAMPLE 7.1 Automatic variable replacement on load In this example, the variables in sales.svg are automatically replaced by the data values in myData.xml. EXAMPLE 7.2 Automatic variable replacement from the command line This command replaces the variables in the SVG file template.svg, then saves it to a new file named "Untitled." It does not execute any other commands. ADS -source template.svg -data myData.xml Replacing Variables Explicitly Use the applyVariables command to replace variable values explicitly at any point during the execution of the command set, after loading and naming both the replacement data and the file containing the variables. If you load the replacement data using the loadContent command (rather than passing it in as part of the request) you must name it using the out attribute: ● If you use the reserved name data, it is the same as passing the replacement data on the command line or with the request; ADS automatically applies that data to any SVG or PSD file that you load. The name data is also the default data content name for the applyVariables command. If you have named the content data, you need not specify the data attribute in the command. ● If you use any name other than the reserved name data, you must pass the name in the data attribute of the applyVariables command in order to apply those values to SVG or PSD content. It is not necessary to name the source file containing the variables, as long as it is the current content when the applyVariables command executes. However, if you name it with the out attribute of the loadContent command, you can make it current by specifying that name with the in attribute of the applyVariables command. When you replace variables explicitly, you can load the files in any order, and perform other manipulations before or after the variable replacement. This differs from automatic variable replacement, where the data file must be loaded first, and the replacement is performed immediately after the file containing variables is loaded. NOTE: When setting up the template file and data file loads, take automatic replacement into account to avoid replacing variable values twice with the same data. For further information on the applyVariables command, see the Adobe Document Server Command Reference. 134 Dec 19, 2003 Adobe Document Server Developers Guide Replacing Variables in SVG and PSD Files Replacing Variables Explicitly 7 EXAMPLE 7.3 Loading multiple data sets for a single template file This example loads a single SVG template file, then replaces the variables with three different sets of data, writing out a new GIF file each time. EXAMPLE 7.4 Streaming in replacement data In this example, a command set loads replacement data inline in a loadContent command, naming the XML content newData. It then loads the source PSD file containing the variables, and uses the applyVariables command to explicitly replace the variable values in the file with the new data. This example replaces variables of types image replacement and text replacement. Adobe Document Server Developers Guide Dec 19, 2003 135 Replacing Variables in SVG and PSD Files Variable Replacement Error Behavior 7 Specifying Replacement Data Specifying Replacement Data A replacement data file is an XML file containing variable replacement values inside a data element. Each replacement value is contained in a subelement named for the variable. For example: Variable Replacement Error Behavior ADS expects the source SVG or PSD file to contain a variable definition to match every replacement value found in the data. ● If the data file contains a variable name that is not defined in the destination SVG or PSD file, ADS reports an error. ● If any variable value is missing from the data file, ADS reports a warning, and the variable value in the destination file remains unchanged. The data file need not replace every variable defined in the destination file. Any variable that is not mentioned in the replacement data remains unchanged. You are responsible for providing data in the correct format for the file format and variable type that you want to replace. ADS does not distinguish between SVG and PSD replacement data, or validate the replacement data. If you specify an existing variable in the replacement data, ADS replaces the bound element with the provided replacement value. If the replacement value is not in the correct format, the resulting file may be syntactically incorrect. SVG Variable Replacement Syntax You can set variables that reference standard elements of the SVG file, as well as variables that allow easy and convenient modification of the graphing, text flow, and image replacement Adobe foreign object extensions. In a source SVG file, variable definitions are stored in the metadata portion of the file. A set of variable bindings defines the attributes and elements that can be replaced with specific data. Variable replacement data in an XML file is enclosed in a data element. The file contains an element for each variable to be replaced, where the name of the element corresponds to the 136 Dec 19, 2003 Adobe Document Server Developers Guide SVG Variable Replacement Syntax Replacing Variables in SVG and PSD Files Specifying Replacement Data 7 name of the variable. You set the variable names outside ADS, in Illustrator. The replacement value that you provide must be appropriate to the variable type: ● For a simple variable bound to an attribute, the replacement value is the new attribute value. ● The replacement value for a visibility variable is the new visibility value, true or false. ● The replacement value for an image replacement variable is the new embedded image data, or a file reference to the new referenced image file. ● For text and graph variables, the variable-name element contains the new element and its subelements with which to replace the original element, as shown in the examples below. A graph variable can be replaced by new graph data in the full graph syntax, as shown in “Replacing a graph variable” on page 139, or in an abbreviated syntax, as shown in “Abbreviated graph syntax data” on page 140. A text variable can be replaced at four different levels of the text flow hierarchy: – If the replacement data value is a flow element, ADS replaces the flow element in the source content with the new flow element. – If the replacement data value is text only, ADS replaces the text of the first span element of the first p element (or the text of the first p, if it has no span) of the flow element in the source content with the new text. It removes all other span and p elements. – If the replacement data value is a p element, ADS replaces all the child elements of the flow element with the new p element. – If the replacement data value is a span element, ADS replaces all the child elements of the first p element of the flow element with the new span element. It is possible to generate replacement data files programmatically by queries to a database, or by wrapping a series of user inputs into an XML file in the correct format. EXAMPLE 7.5 Basic variable replacement The source SVG file contains a simple variable named fillcolor1 that is bound to the fill attribute of a circle. The following replacement data specifies a value of red for the variable: Adobe Document Server Developers Guide Dec 19, 2003 137 Replacing Variables in SVG and PSD Files SVG Variable Replacement Syntax 7 Specifying Replacement Data EXAMPLE 7.6 Replacing a visibility variable The source SVG file contains a variable of type visibility with the name showimage, bound to the element Image1. In the SVG, this trait is actually controlled by the display attribute, which has a value of inline or none. This replacement data specifies a value of true for the variable showimage, which causes ADS to set the value of Image1/@display to inline. EXAMPLE 7.7 Replacing an image variable with an image file reference The source SVG file contains a variable of type image replacement with the name newimage, bound to the element Image2. EXAMPLE 7.8 Replacing an image variable with embedded image data The source SVG file contains a variable of type image replacement with the name newimage, This example replaces the image with base-64 encoded image data, which the command writes to an optimized format and embeds in the file. 138 Dec 19, 2003 Adobe Document Server Developers Guide SVG Variable Replacement Syntax Replacing Variables in SVG and PSD Files Specifying Replacement Data 7 EXAMPLE 7.9 Replacing a graph variable The source SVG file contains a variable of type graph with the name newsalesdata, bound to the graph object named Sales1. This replacement data specifies data and values subelements as values of the newsalesdata variable. ADS uses that information to replace the values of /Sales1/foreignObject/graphdata and /Sales1/foreignObject/graph/values. Adobe Document Server Developers Guide Dec 19, 2003 139 Replacing Variables in SVG and PSD Files SVG Variable Replacement Syntax 7 Specifying Replacement Data EXAMPLE 7.10 Abbreviated graph syntax data Here is an example of abbreviated data file syntax, shown for the variable newsalesdata from the previous example. Note that there must be a comma preceding the first line of data, which reserves a spot for the name of a row title. Semicolons delimit the values. EXAMPLE 7.11 Replacing text using a text variable The source SVG file contains a variable of type text with the name newcaption, bound to the text object named Caption1. or subelement) to that value. EXAMPLE 7.12 Replacing text attributes using a text variable The source SVG file contains a variable of type text with the name newSamples, bound to the text object named SampleColors. Sample 1: Red 140 Dec 19, 2003 Adobe Document Server Developers Guide PSD Variable Replacement Syntax Replacing Variables in SVG and PSD Files Specifying Replacement Data 7 PSD Variable Replacement Syntax Unlike SVG, PSD is a binary format. When you load a PSD file into ADS, you can access and manipulate certain features using an abbreviated XPath syntax with the set command. ADS translates the elements and attributes that you set in this way to and from their PSD-format equivalents. Only a limited set of features are accessible through the set command. You can use ImageReady 7 to create and bind variables of the following types: ● visibility: The variable can be bound to an image, a layer, or a layer set. The replacement value is true or false. ● text replacement: The variable can be bound to the text flow in a text layer. The replacement value is simple text, which replaces all of the text in the layer. Text attributes such as the font are unchanged. For more information on text replacement methods and text flows, see Chapter 6, “Changing Text in Images.” ● pixel replacement: The variable can be bound to an image in an image layer. The replacement value is a new image file specification, where the file is accessible to the ADS server process, or the new image in base-64 encoded format. When ADS replaces an image value for a pixel-replacement variable, it uses the same mechanism as the replacePixels command, but with position and scaling settings that match those set in the Variables dialog box in ImageReady. EXAMPLE 7.13 Replacing a visibility variable The source PSD file contains a variable of type visibility with the name showimage. This replacement data sets the value to true. Adobe Document Server Developers Guide Dec 19, 2003 141 Replacing Variables in SVG and PSD Files PSD Variable Replacement Syntax 7 Specifying Replacement Data EXAMPLE 7.14 Replacing a text variable The source PSD file contains a variable of type text replacement with the name caption. This replacement data sets the value to "new title". EXAMPLE 7.15 Replacing a pixel variable using a file reference The source PSD file contains a variable of type pixel replacement with the name product. This replacement data sets the value to the contents of the referenced JPEG file. ADS resolves the relative path to that file with respect to the base input URI. EXAMPLE 7.16 Replacing a pixel variable with an embedded image The source PSD file contains a variable of type pixel replacement with the name product. This example loads a replacement image in base-64 encoded format, giving it the reserved name data. When it loads the source PSD file, the pixel value is replaced automatically with the new image data. The example then saves the file with the new image value to an optimized format (as determined by its optimization settings). 142 Dec 19, 2003 Adobe Document Server Developers Guide PSD Variable Replacement Syntax Replacing Variables in SVG and PSD Files Specifying Replacement Data 7 The Automatic Text Variable For any PSD file with one or more text layers, ADS defines a PSD variable named defaultTextLayer. This allows you to automatically replace the text in the topmost text layer upon loading the file into ADS, without having to first define such a variable outside ADS. (The topmost layer is the one with the highest index number.) For more information, see the Adobe Document Server Command Reference. EXAMPLE 7.17 Replacing the default text variable To replace the text in the topmost text layer, specify the new text value for the default variable named defaultTextVariable in the XML replacement data: Adobe Document Server Developers Guide Dec 19, 2003 143 Replacing Variables in SVG and PSD Files PSD Variable Replacement Syntax 7 Specifying Replacement Data 144 Dec 19, 2003 Adobe Document Server Developers Guide 8 Operations Specific to SVG Files This chapter covers a series of topics relating to the manipulation of SVG files. It includes the following sections: Overview starting on page 145 Foreign Objects starting on page 145 SVG Font Considerations starting on page 148 Illustrator SVG Template Tips starting on page 149 Converting SVG to Raster starting on page 151 Converting SVG to PDF starting on page 151 Overview To successfully use SVG files with ADS, you need to understand the concept of foreign objects in SVG and the way that Adobe uses the concept within ADS. Foreign objects require corresponding SVG renderers, which may handle graphing, text flows, or images. There are some considerations about fonts within SVG files that you need to be aware of to ensure that fonts are properly referenced and/or embedded and that the references are resolved. In addition, there are techniques you can use with Illustrator that will simplify the task of creating ADS command sets to manipulate the SVG file. One of the primary destinations for SVG source material is to convert them into PDF. The convertSVGToPDF command, described in “Converting SVG to PDF” on page 151, accomplishes this. For details of how individual SVG elements are converted to PDF, see the Adobe Document Server Command Reference. Foreign Objects ADS uses the concept of a foreign object from the SVG specification to extend the functionality of basic SVG. A foreign object is used to describe an object outside the SVG specification. A foreign object is an XML description of an object, such as a graph. The SVG specification defines a plug-in type of rendering architecture. If an SVG renderer encounters a reference to a foreign object in an SVG file, it searches its list of pluggable extensions. If the renderer finds a proper rendering extension, it calls the plug-in to render the foreign object. When an SVG renderer such as ADS encounters a foreign object, it looks in its list of renderers for one that can render the object. Adobe Document Server Developers Guide Dec 19, 2003 145 Operations Specific to SVG Files Graph Foreign Object 8 Foreign Objects Foreign objects are typically wrapped in a switch element in an SVG file. As the SVG renderer processes the file, when it encounters a switch containing a foreign object, the renderer determines whether or not it can interpret that foreign object. The renderer will render the first foreign object within the switch that it recognizes. If the renderer cannot interpret any of the foreign objects in the switch, it will render the default group of the switch. This means that even complex files with multiple foreign objects can still be rendered with even the most basic SVG renderers. For instance, if you exported a file from Illustrator that contained a graph, a third-party renderer (for example, an SVG viewer not provided by Adobe) might not be able to render the Illustrator-generated foreign object. Therefore, a traditional SVG representation of the graph is included as the last branch of the switch element. When the third-party renderer fails to render the Adobe foreign object, the SVG renderer resorts to rendering standard SVG. The syntax and structure of using a switch element in this way is described in more detail in “Graph Objects in ADS” on page 159. When ADS interprets the foreign object and makes data and format transformations on that object, it substitutes the resulting SVG description for the original default. Thus the resulting SVG file can be rendered in its transformed form by standard SVG renderers. Adobe has defined foreign objects that describe sophisticated graphing, flexible text handling capability (text flows), and enhanced image replacement. Adobe provides renderers that handle these types of foreign objects. Graph Foreign Object ADS supports a specialized graph foreign object for SVG files. A graph foreign object is used for graphs that contain data replaced through variable replacement. A graph foreign object specifies a set of data to be graphed and a set of formatting instructions that describe how the data should be converted into a graph. A graph foreign object is described in an SVG file within a foreignObject element, usually embedded inside of a switch element. The graph replacement foreignObject contains two elements: ● The graph element. This element describes how to render the graph. It usually includes separate data and format sub-elements. ● The targetRef element. This element references the target element, which is the default SVG version, such as the template image created by Illustrator. The requiredExtension attribute of the graphing foreignObject is set to the “http://ns.adobe.com/Graphs/1.0/” namespace. The graphdescr element is defined in this same namespace. For more information on graphs and to view an example, refer to the “XML Grammar for Graphing” chapter in the Adobe Document Server XML Grammars Reference. The targetRef element is in the “http://ns.adobe.com/Extensibility/1.0/” namespace. For further information, see the “XML Grammar for Object Extensibility” chapter in the Adobe Document Server XML Grammars Reference. 146 Dec 19, 2003 Adobe Document Server Developers Guide Text Flow Foreign Object Operations Specific to SVG Files Foreign Objects 8 Text Flow Foreign Object ADS supports a specialized text flow foreign object for source SVG files. A text flow foreign object is typically used for text flows replaced via variable replacement. A text flow foreign object is described in an SVG file within a foreignObject element embedded inside of a switch element. The text flow replacement foreignObject contains two elements: ● The flowDef element — This element describes how to render the text flow. ● The targetRef element — This element references the target element, which is a text element, that is to be modified per the definition of the flowDef element. The requiredExtension attribute of the image replacement foreignObject is set to the “http://ns.adobe.com/Flows/1.0/” namespace. The flowDef element is defined in this same namespace. For more information on text flows and to view an example, refer to the “Accessing Raster Content” chapter in the Adobe Document Server XML Grammars Reference. The targetRef element is in the “http://ns.adobe.com/Extensibility/1.0/” namespace. For further information, see the chapter “XML Grammar for Object Extensibility” in the Adobe Document Server XML Grammars Reference. Image Replacement Foreign Objects ADS supports a specialized image replacement foreign object for source SVG files. An image replacement foreign object is typically used for images replaced via variable replacement. An image replacement foreign object can control more than just the image to use as a replacement. It also controls how the image is to be replaced, such as whether to use fit, fill, or ratio replacement. In addition, the object controls where to position the new image relative to the original image. An image replacement foreign object is described in an SVG file within a foreignObject element embedded in a switch element. The image replacement foreign object contains two elements: ● The imageReplacement element. This element describes how to render the image. ● The targetRef element. This element references the target element, which is an image element, that is to be modified per the definition of the imageReplacement element. The requiredExtension attribute of the image replacement foreignObject is set to the “http://ns.adobe.com/ImageReplacement/1.0/” namespace. The imageReplacement element is defined in this same namespace. For more information on image replacement, and to view an example, refer to the “XML Grammar for Image Replacement” chapter in the Adobe Document Server XML Grammars Reference. The targetRef element is in the “http://ns.adobe.com/Extensibility/1.0/” namespace. For further information, refer to the “XML Grammar for Object Extensibility” chapter in the Adobe Document Server XML Grammars Reference. Adobe Document Server Developers Guide Dec 19, 2003 147 Operations Specific to SVG Files Embedded Fonts in SVG 8 SVG Font Considerations SVG Font Considerations This section discusses font behavior and caveats with regard to the SVG file format. This section discusses: ● Embedded fonts in SVG ● Resolving font references within SVG For information on installing and configuring fonts, refer to the ADS Installation and Configuration Guide. Embedded Fonts in SVG SVG files can reference external fonts, or they can contain the required font information in embedded fonts. Embedded fonts might not include font information for all glyphs within a font, which can affect results if the text is changed to require additional glyphs. Embedded fonts can be referenced by text within text and span elements. If you are manipulating text that is not part of a text flow (that is, text that is not contained within a flowDef foreign object), ADS uses and preserves any embedded fonts. In case you make changes in the text that requires additional glyphs not previously embedded, make sure the fonts required are available and indicated to ADS. For further information on installing and configuring fonts, refer to the ADS Installation and Configuration Guide. Embedded fonts cannot be used by text within text flow elements. If you are manipulating a text flow that uses embedded fonts, the embedded fonts are ignored. If you plan to manipulate flow text in an SVG file, do not embed any fonts, since the fonts are never used and only add extraneous bytes to the file size. Resolving Font References within SVG Any font references made from within an SVG file are resolved relative to the location of the SVG file itself. Once inside the SVG file, the location of the ADS commands is no longer relevant. This behavior mirrors what happens in HTML. When you open a new page in your browser, all relative references on that new page are resolved relative to the location of the new page. For example, assume you have a command file located in /my/directory/location/ADS/commands.xml. Your command file contains the following: 148 Dec 19, 2003 Adobe Document Server Developers Guide Naming Shapes and Layers Operations Specific to SVG Files Illustrator SVG Template Tips 8 Also assume that the file referenced in the loadContent command is an SVG file residing in /my/directory/location/svg/mysvg.svg. The relative path in the command file properly accesses this file. An excerpt of this file is shown here. Note the relative location for the fonts.