- Viewing Photoshop CS2 objects, commands, and methods
- Creating new objects in a script
- Setting the active object
- Opening a document
- Saving a document
- Setting application preferences
- Suppressing dialog boxes
- Working with the Adobe Photoshop CS2 Object Model
- Working with color objects
- Working with filters
- Understanding clipboard interaction
- Working with units
- Sample workflow automation JavaScripts
- Advanced scripting
Opening a document
You use the open() method of the Application object to open an existing document. You must specify the document name (that is, the path to the file that contains the document) with the method.
Specifying file formats to open
Because Adobe Photoshop CS2 supports many different file formats, the open() method lets you specify the format of the document you are opening. If you do not specify the format, Adobe Photoshop CS2 will infer the type of file for you. The following example opens a document using its default type:
var fileRef = new File("//MyFile") var docRef = app.open (fileRef)
Notice that you must create a File object and then pass a reference to the object to the open() command.
For the document types on the following list, you can set options to specify how the document will be opened, such as the height and width of the window in which the document is opened, which page to open to in a multi-page file, etc.
- PhotoCD
- CameraRaw
- RawFormat
- Adobe PDF
- EPS
To find out which options you can set for each of file type, look up the properties for the OpenOptions objects that begin with the file format name. For example, look up PhotoCDOpenOptions or EPSOpenOptions in the scripting reference (Part 2).
The following example demonstrates how to open a generic (multi-page/multi-image) PDF document with the following specifications:
- The document will open in a window that is 100 pixels high and 200 pixels wide.
- The document will open in RGB mode with a resolution of 72 pixels/inch.
- Antialiasing will be used to minimize the jagged appearance of the edges of images in the document.
- The document will open to page 3.
- The document’s original shape will change to conform to the height and width properties if the original shape is not twice
as wide as it is tall.
// Set the ruler units to pixels var originalRulerUnits = app.preferences.rulerUnits app.preferences.rulerUnits = Units.PIXELS // Get a reference to the file that we want to open var fileRef = new File( C:\\PDFFiles\MyFile.pdf ) // Create a PDF option object var pdfOpenOptions = new PDFOpenOptions pdfOpenOptions.antiAlias = true pdfOpenOptions.height = 100 pdfOpenOptions.width = 200 pdfOpenOptions.mode = OpenDocumentMode.RGB pdfOpenOptions.resolution = 72 pdfOpenOptions.page = 3 pdfOpenOptions.constrainProportions = false // open the file app.open( fileRef, pdfOpenOptions ) // restore unit settings app.preferences.rulerUnits = originalRulerUnits