Edit in GitHubLog an issue

Document

Represents a single Photoshop document that is currently open You can access instances of documents using one of these methods:

Copied to your clipboard
// The currently active document from the Photoshop object
const currentDocument = app.activeDocument
// Choose one of the open documents from the Photoshop object
const secondDocument = app.documents[1]
// You can also create an instance of a document via a UXP File entry
let fileEntry = require('uxp').storage.localFileSystem.getFileForOpening()
const newDocument = await app.open('/project.psd')

Accessors

activeLayers

get activeLayers(): Layer[]

The selected layers in the document

Copied to your clipboard
const layers = doc.activeLayers;
const topLayer = layers[0]

backgroundLayer

get backgroundLayer(): Layer | null

Background layer, if it exists

Copied to your clipboard
const bgLayer = currentDocument.backgroundLayer

height

get height(): number

Document's height in pixels


layerTree

get layerTree(): LayerTypes[]

Top level layers in the document


layers

get layers(): LayerTypes[]

All the layers in the document, in a flat list

Copied to your clipboard
const layers = currentDocument.layers
const topLayer = layers[0]

path

get path(): string

Path to this document, or it's identifier if a cloud document


resolution

get resolution(): number

Document's resolution (in pixels per inch)

For example, in the default PS document (7 in wide by 5 in tall at 300 ppi)

Copied to your clipboard
const resolution = doc.resolution // 300
const width = doc.width // 2100
const height = doc.height // 1500

title

get title(): string

Document title

Copied to your clipboard
const currentTitle = doc.title

readonly


width

get width(): number

Document's width in pixels

Methods

close

close(saveDialogOptions?: SaveDialogOptions): Promise‹void›

Closes the document, showing a prompt to save unsaved changes if specified

async

Parameters:

NameType
saveDialogOptions?
SaveDialogOptions

closeWithoutSaving

closeWithoutSaving(): void


createLayer

createLayer(options?: LayerCreateOptions): Promise‹Layer | null›

Create a layer. See @CreateOptions

Copied to your clipboard
const myEmptyLayer = await doc.createLayer()
const myLayer = await doc.createLayer({ name: "myLayer", opacity: 80, mode: "colorDodge" })

async

Parameters:

NameType
options?
LayerCreateOptions

createLayerGroup

createLayerGroup(options?: GroupLayerCreateOptions): Promise‹GroupLayer | null›

Create a layer group. See @CreateOptions

Copied to your clipboard
const myEmptyGroup = await doc.createLayerGroup()
const myGroup = await doc.createLayerGroup({ name: "myLayer", opacity: 80, mode: "colorDodge" })
const nonEmptyGroup = await doc.createLayerGroup({ name: "group", fromLayers: [layer1, layer2] })

async

Parameters:

NameType
options?
GroupLayerCreateOptions

crop

crop(bounds: PsCommon.Bounds, angle: number): Promise‹void›

Crops the document to given bounds

async

Parameters:

NameTypeDefaultDescription
bounds
PsCommon.Bounds
-
-
angle
number
0

duplicateLayers

duplicateLayers(layers: Layer[], targetDocument?: Document): Promise‹Layer[]›

Duplicates given layer(s), creating all copies above the top most one in layer stack, and returns the newly created layers.

Copied to your clipboard
// duplicate some layers
const layerCopies = await document.duplicateLayers([layer1, layer3])
layerCopies.forEach((layer) => { layer.blendMode = 'multiply' })
// ...to another document
const finalDoc = await photoshop.open('~/path/to/collated/image.psd')
await document.duplicateLayers([logo1, textLayer1], finalDoc)
await finalDoc.close(SaveDialogOptions.SAVE_CHANGES)

async

Parameters:

NameTypeDescription
layers
-
targetDocument?
if specified, duplicate to a different document target.

flatten

flatten(): Promise‹void›

Flatten all layers in the document

async


groupLayers

groupLayers(layers: Layer[]): Promise‹GroupLayer | null›

Create a layer group from existing layers.

Copied to your clipboard
const layers = doc.layers
const group = await doc.groupLayers([layers[1], layers[2], layers[4]])

async

Parameters:

NameType
layers

linkLayers

linkLayers(layers: Layer[]): Layer[]

Links layers together if possible, and returns a list of linked layers.

Parameters:

NameTypeDescription
layers
array of layers to link together

array of successfully linked layers


mergeVisibleLayers

mergeVisibleLayers(): Promise‹void›

Flattens all visible layers in the document

async


resizeCanvas

resizeCanvas(width: number, height: number, anchor?: AnchorPosition): Promise‹void›

Changes the size of the canvas, but does not change image size To change the image size, see resizeImage

Copied to your clipboard
// grow the canvas by 400px
let width = await document.width
let height = await document.height
await document.resizeCanvas(width + 400, height + 400)

async

Parameters:

NameTypeDescription
width
number
Numeric value of new width in pixels
height
number
Numeric value of new height in pixels
anchor?
AnchorPosition
Anchor point for resizing, by default will resize an equal amount on all sides.
Of format:
[top/middle/bottom]-[left/center/right]

resizeImage

resizeImage(width: number, height: number, resolution?: number, resampleMethod?: ResampleMethod): Promise‹void›

Changes the size of the image

Copied to your clipboard
await document.resizeImage(800, 600)

async

Parameters:

NameTypeDescription
width
number
Numeric value of new width in pixels
height
number
Numeric value of new height in pixels
resolution?
number
Image resolution in pixels per inch (ppi)
resampleMethod?
ResampleMethod
Method used during image interpolation.
Possible values are:
  • nearestNeighbor
  • bilinear
  • bicubic
  • bicubicSmoother
  • bicubicSharper
  • bicubicAutomatic
  • preserveDetailsUpscale
  • deepUpscale

rotate

rotate(angles: number): Promise‹void›

Rotates the image clockwise in given angle, expanding canvas if necessary

async

Parameters:

NameType
angles
number

save

save(entry?: File, saveOptions?: SaveOptions): Promise‹void›

Saves the document or a copy, the format is deduced by the extension

Copied to your clipboard
// To save a document in the same location
document.save()
// Shows the save dialog
unsavedDocument.save()
// To save to a path, use UXP storage APIs to get a file for saving
let entry = await require('uxp').storage.localFileSystem.getFileForSaving("target.psd")
document.save(entry)
// To save to a path, but with some options:
document.save(entry, { embedColorProfile: true })

async

Parameters:

NameType
entry?
File
saveOptions?
SaveOptions
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2026 Adobe. All rights reserved.