Adobe 65015634 Scripting Guide - Page 30

JavaScript Tools Guide, The ExtendScript

Page 30 highlights

CHAPTER 3: Scripting Photoshop Opening a Document 30 AS VBS JS ➤ 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. 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 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 NOTE: 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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87

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