C
HAPTER
3: Scripting Photoshop
Opening a Document
30
➤
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.
AS
tell application "Adobe Photoshop CS4"
set myFilePath to alias "OS X 10.4.8 US:Users:psauto:Desktop:opal_screen.pdf"
with timeout of 300 seconds
open myFilePath as PDF with options ¬
{class:PDF open options, ¬
mode:RGB, resolution:72, use antialias:true, page:3}
end timeout
end tell
VBS
Dim appRef
Set appRef = CreateObject("Photoshop.Application")
'Remember unit settings and set to values expected by this script
Dim originalRulerUnits
originalRulerUnits = appRef.Preferences.RulerUnits
appRef.Preferences.RulerUnits = 1 'value of 1 = psPixels
'Create a PDF option object
Dim pdfOpenOptionsRef
Set pdfOpenOptionsRef = CreateObject("Photoshop.PDFOpenOptions")
pdfOpenOptionsRef.AntiAlias = True
pdfOpenOptionsRef.Mode = 2 ' psOpenRGB
pdfOpenOptionsRef.Resolution = 72
pdfOpenOptionsRef.Page = 3
' open the file
Dim docRef
Set docRef = appRef.Open(“C:\\PDFFiles\MyFile.pdf”, pdfOpenOptionsRef)
'Restore unit setting
appRef.Preferences.RulerUnits = originalRulerUnits
JS
N
OTE
:
The ExtendScript
File
object expects Universal Resource Identifier (URI) notation. Please see the
JavaScript Tools Guide
for more information.
// 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.mode = OpenDocumentMode.RGB
pdfOpenOptions.resolution = 72
pdfOpenOptions.page = 3
// open the file
app.open( fileRef, pdfOpenOptions )
// restore unit settings
app.preferences.rulerUnits = originalRulerUnits