# Matrix Class

> A transformation matrix in a PDF file is specified by six numbers.

- Product: Adobe PDF Library 18
- Language: Java
- Version: APDFL18.0.5PlusP2e
- HTML page: https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix
- Version index: https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/llms.txt

```java
class Matrix
```

**Namespace:** `com::datalogics::PDFL`

## Description

A transformation matrix in a PDF file is specified by six numbers. The matrix is usually in the form of an array containing the six elements [a b c d h v].

A translation is specified as [ 1 0 0 1 tx ty], where tx and ty are the distance to translate from the origin of the coordinate system in the horizontal and vertical dimension, respectively.

A scaling is obtained by [sx 0 0 sy 0 0]. This scales the coordinates so that 1 unit in the horizontal and vertical dimension of the new coordinate system is the same size as sx and sy units, respectively, as in the previous coordinate system.

A rotation is produced by [ cos T sin T -sin T cos T 0 0 ], which has the effect of rotating the coordinate system axes by an angle T (degrees) counterclockwise.

This material indicates that the matrix specifying a transformation is premultiplied with the current transformation matrix, i.e.,

M' = Mt * M

The implementation of the Scale, Rotate, and Translate convenience functions of Matrix reflect the same order of operations, so that they are consistent with the PDF Reference manual. They are also consistent with the scale, rotate, and translate operators in PostScript, from which the coordinate system model in PDF is derived.

**Referenced by:** [`Container`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Container.md), [`Content`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Content.md), [`DrawParams`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/DrawParams.md), [`Element`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Element.md), [`Form`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Form.md), [`Group`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Group.md), [`Image`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Image.md), [`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md), [`Page`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Page.md), [`Path`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Path.md), [`Point`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Point.md), [`PostScript`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/PostScript.md), [`Quad`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Quad.md), [`Rect`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Rect.md), [`Shading`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Shading.md), [`Text`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Text.md), [`TextRun`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/TextRun.md)

**Uses types:** [`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)

## Constructors

### Matrix

```java
com.datalogics.PDFL.Matrix.Matrix()
```

*constructor*

the default constructor creates a transformation matrix to translate the rectangle 1 element (1/72nd of an inch) from the origin.

### Matrix

```java
com.datalogics.PDFL.Matrix.Matrix(double na, double nb, double nc, double nd, double nh, double nv)
```

*constructor*

**Parameters**

- `na` (`double`): The horizontal scaling component (a).
- `nb` (`double`): The vertical shearing component (b).
- `nc` (`double`): The horizontal shearing component (c).
- `nd` (`double`): The vertical scaling component (d).
- `nh` (`double`): The horizontal translation component (h).
- `nv` (`double`): The vertical translation component (v).

Construct a Matrix with the specified component values.

## Methods

### concat

```java
Matrix com.datalogics.PDFL.Matrix.concat(Matrix Mt)
```

**Parameters**

- `Mt` ([`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)): The matrix to concatenate (premultiply) onto this matrix.

**Returns:** [`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)

the transformed matrix

Concatenate a matrix onto an existing matrix. The product returned is:

M' = Mt * M

This corresponds to the action of the cm operator.

### delete

```java
synchronized void com.datalogics.PDFL.Matrix.delete(Boolean disposing)
```

*protected*

**Parameters**

- `disposing` (`Boolean`)

**Returns:** `synchronized void`

### delete

```java
synchronized void com.datalogics.PDFL.Matrix.delete()
```

**Returns:** `synchronized void`

### equals

```java
boolean com.datalogics.PDFL.Matrix.equals(Object rhs)
```

**Parameters**

- `rhs` (`Object`)

**Returns:** `boolean`

### finalize

```java
void com.datalogics.PDFL.Matrix.finalize()
```

*protected*

**Returns:** `void`

### getA

```java
double com.datalogics.PDFL.Matrix.getA()
```

**Returns:** `double`

The horizontal scaling component of the matrix.

### getB

```java
double com.datalogics.PDFL.Matrix.getB()
```

**Returns:** `double`

The vertical shearing component of the matrix.

### getC

```java
double com.datalogics.PDFL.Matrix.getC()
```

**Returns:** `double`

The horizontal shearing component of the matrix.

### getD

```java
double com.datalogics.PDFL.Matrix.getD()
```

**Returns:** `double`

The vertical scaling component of the matrix.

### getH

```java
double com.datalogics.PDFL.Matrix.getH()
```

**Returns:** `double`

The horizontal translation component of the matrix.

### getV

```java
double com.datalogics.PDFL.Matrix.getV()
```

**Returns:** `double`

The vertical translation component of the matrix.

### invert

```java
Matrix com.datalogics.PDFL.Matrix.invert()
```

**Returns:** [`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)

The inverted matrix.

Invert the Matrix object and return a new Matrix object.

### multiply

```java
static Matrix com.datalogics.PDFL.Matrix.multiply(Matrix m1, Matrix m2)
```

*static*

**Parameters**

- `m1` ([`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)): a matrix
- `m2` ([`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)): a matrix

**Returns:** [`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)

the matrix product m1 x m2

Multiply two transformation matrices.

### rotate

```java
Matrix com.datalogics.PDFL.Matrix.rotate(double T)
```

**Parameters**

- `T` (`double`): The rotation, counterclockwise

**Returns:** [`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)

the result [cos T sin T -sin T 0 0] * M

Rotate a matrix by T degrees counterclockwise units. Rotation is done by creating the matrix [ cos T sin T -sin T cos T 0 0 ], and calling the Concat function with that matrix.

### scale

```java
Matrix com.datalogics.PDFL.Matrix.scale(double sx, double sy)
```

**Parameters**

- `sx` (`double`): X scaling factor
- `sy` (`double`): Y scaling factor

**Returns:** [`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)

the result [sx 0 0 sy 0 0] * M

Scale a matrix by (sx,sy) units. Scaling is done by creating the matrix [sx 0 0 sy 0 0], and calling the Concat function with that matrix.

### setA

```java
void com.datalogics.PDFL.Matrix.setA(double value)
```

**Parameters**

- `value` (`double`)

**Returns:** `void`

The horizontal scaling component of the matrix.

### setB

```java
void com.datalogics.PDFL.Matrix.setB(double value)
```

**Parameters**

- `value` (`double`)

**Returns:** `void`

The vertical shearing component of the matrix.

### setC

```java
void com.datalogics.PDFL.Matrix.setC(double value)
```

**Parameters**

- `value` (`double`)

**Returns:** `void`

The horizontal shearing component of the matrix.

### setD

```java
void com.datalogics.PDFL.Matrix.setD(double value)
```

**Parameters**

- `value` (`double`)

**Returns:** `void`

The vertical scaling component of the matrix.

### setH

```java
void com.datalogics.PDFL.Matrix.setH(double value)
```

**Parameters**

- `value` (`double`)

**Returns:** `void`

The horizontal translation component of the matrix.

### setV

```java
void com.datalogics.PDFL.Matrix.setV(double value)
```

**Parameters**

- `value` (`double`)

**Returns:** `void`

The vertical translation component of the matrix.

### toString

```java
String com.datalogics.PDFL.Matrix.toString()
```

**Returns:** `String`

A string describing this Matrix and its component values.

Returns a string representation of this Matrix. The returned string contains all six matrix components (a, b, c, d, h, v) in a human-readable format.

### translate

```java
Matrix com.datalogics.PDFL.Matrix.translate(double tx, double ty)
```

**Parameters**

- `tx` (`double`): X translation distance
- `ty` (`double`): Y translation distance

**Returns:** [`Matrix`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Matrix.md)

the result [1 0 0 1 tx ty] * M

Translate a matrix by (tx,ty) units. Translation is done by creating the matrix [ 1 0 0 1 tx ty ], and calling the Concat function with that matrix.
