# PdfPageCollection

## Content

# Class: PdfPageCollection

Represents a collection of pages that make up a PDF document.

## Extends

- `PdfCollection`&lt;[`PdfPage`](PdfPage)&gt;

## Accessors

### count

#### Get Signature

```ts
get count(): number;
```

Gets the number of items in the collection.

##### Returns

`number`

#### Overrides

```ts
PdfCollection.count
```

***

### doc

#### Get Signature

```ts
get doc(): PdfDocument;
```

Gets the owner PdfDocument.

##### Returns

[`PdfDocument`](PdfDocument)

***

### id

#### Get Signature

```ts
get id(): number;
```

Gets the reference to the object.

##### Returns

`number`

#### Inherited from

```ts
PdfCollection.id
```

***

### last

#### Get Signature

```ts
get last(): TItem;
```

Gets last item in the collection.

##### Returns

`TItem`

#### Inherited from

```ts
PdfCollection.last
```

***

### om

#### Get Signature

```ts
get om(): ObjectManager;
```

Gets the owner [ObjectManager](ObjectManager) instance.

##### Returns

[`ObjectManager`](ObjectManager)

#### Inherited from

```ts
PdfCollection.om
```

## Methods

### add()

```ts
add(item): void;
```

Adds an item to the end of the collection.

#### Parameters

##### item

[`PdfPage`](PdfPage)

The item to add.

#### Returns

`void`

#### Inherited from

```ts
PdfCollection.add
```

***

### addNew()

#### Call Signature

```ts
addNew(): PdfPage;
```

Adds a new PdfPage to the end of the collection.

##### Returns

[`PdfPage`](PdfPage)

A PdfPage object added to the collection.

#### Call Signature

```ts
addNew(width, height): PdfPage;
```

Creates a new PdfPage with the specified size and adds it to the end of the collection.

##### Parameters

###### width

`number`

The width of the new page, in points.

###### height

`number`

The height of the new page, in points.

##### Returns

[`PdfPage`](PdfPage)

A PdfPage object added to the collection.

##### Example

```ts
const doc = new PdfDocument();
const page = doc.pages.addNew(500, 350);
page.context.drawEllipse(100, 100, 300, 150, {
    fillColor: "MediumAquamarine",
    lineColor: "Teal",
    lineWidth: 10
});
const res: Uint8Array = doc.savePdf();
```

***

### clear()

```ts
clear(): void;
```

Clears the collection.

#### Returns

`void`

#### Overrides

```ts
PdfCollection.clear
```

***

### clone()

```ts
clone(
   sourceIndex, 
   destinationIndex, 
   cloneAnnotations?, 
   cloneFields?): void;
```

Clones a page at a specified index (sourceIndex) and inserts it at a specified position (destinationIndex).

#### Parameters

##### sourceIndex

`number`

The index of the page to clone.

##### destinationIndex

`number`

The destination index.

##### cloneAnnotations?

`boolean`

Indicates whether to clone page annotations.

##### cloneFields?

`boolean`

Indicates whether to clone fields existing on the source page.

#### Returns

`void`

***

### contains()

```ts
contains(page): boolean;
```

Determines whether the item is in the collection.

#### Parameters

##### page

[`PdfPage`](PdfPage)

#### Returns

`boolean`

true if the item is in the collection, false otherwise.

#### Overrides

```ts
PdfCollection.contains
```

***

### free()

```ts
free(): void;
```

Detaches the object from the [ObjectManager](ObjectManager) and deallocates its memory, if possible.

#### Returns

`void`

#### Inherited from

```ts
PdfCollection.free
```

***

### getAt()

```ts
getAt(index): PdfPage;
```

Gets the item with the specified index.

#### Parameters

##### index

`number`

The index of the item.

#### Returns

[`PdfPage`](PdfPage)

#### Overrides

```ts
PdfCollection.getAt
```

***

### insert()

```ts
insert(index, page): void;
```

Inserts an item at a specific position in the collection.

#### Parameters

##### index

`number`

The position where the item will be inserted.

##### page

[`PdfPage`](PdfPage)

#### Returns

`void`

#### Overrides

```ts
PdfCollection.insert
```

***

### insertNew()

#### Call Signature

```ts
insertNew(index): PdfPage;
```

Inserts a new PdfPage at a specific position in the collection.

##### Parameters

###### index

`number`

The position where the new page will be inserted.

##### Returns

[`PdfPage`](PdfPage)

A PdfPage object inserted in the collection.

#### Call Signature

```ts
insertNew(
   index, 
   width, 
   height): PdfPage;
```

Creates a new PdfPage with the specified size and inserts it at a specific position in the collection.

##### Parameters

###### index

`number`

The position where the new page will be inserted.

###### width

`number`

The width of the new page, in points.

###### height

`number`

The height of the new page, in points.

##### Returns

[`PdfPage`](PdfPage)

A PdfPage object inserted in the collection.

***

### move()

```ts
move(sourceIndex, destinationIndex): void;
```

Moves a page specified by its 0-based index to another position in the page collection.

#### Parameters

##### sourceIndex

`number`

The current index of the page to move.

##### destinationIndex

`number`

The new index of the page.

#### Returns

`void`

***

### rebind()

```ts
rebind(omTo): void;
```

Rebinds the object from the current [ObjectManager](ObjectManager) to the specified one.

#### Parameters

##### omTo

[`ObjectManager`](ObjectManager)

The new [ObjectManager](ObjectManager) for the object.

#### Returns

`void`

#### Inherited from

```ts
PdfCollection.rebind
```

***

### remove()

```ts
remove(page): boolean;
```

Removes the specified item from the collection.

#### Parameters

##### page

[`PdfPage`](PdfPage)

#### Returns

`boolean`

true if the item was actually removed, false otherwise.

#### Overrides

```ts
PdfCollection.remove
```

***

### removeAt()

```ts
removeAt(index): void;
```

Removes the item at specified index.

#### Parameters

##### index

`number`

The index of the item to remove.

#### Returns

`void`

#### Overrides

```ts
PdfCollection.removeAt
```

***

### setAt()

```ts
setAt(index, page): void;
```

Sets the item at the specified index.

#### Parameters

##### index

`number`

The index of the item, starting from 0.

##### page

[`PdfPage`](PdfPage)

#### Returns

`void`

#### Overrides

```ts
PdfCollection.setAt
```

***

### swap()

```ts
swap(pageIndex1, pageIndex2): void;
```

Swaps two pages specified by their 0-based indices.

#### Parameters

##### pageIndex1

`number`

The index of the first page to swap.

##### pageIndex2

`number`

The index of the second page to swap.

#### Returns

`void`
