How can I help you?
PdfLayerCollection
21 Apr 202613 minutes to read
The class provides methods and properties to handle the collection of PdfLayer.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the collection of layers in the document
let layers: PdfLayerCollection = document.layers;
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Properties
Get count number
Gets the layer count.
Methods
add
Create a new PdfLayer with name
add it to the end of the collection.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the collection of layers in the document
let layers: PdfLayerCollection = document.layers;
// Add a new layer to the document with the name 'Layer1'
let layer: PdfLayer = layers.add('Layer1');
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| name | string |
Name of the layer. |
Returns PdfLayer
add
Create a new PdfLayer with name and Boolean flag to set the visibility of layer
add it to the end of the collection.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the collection of layers in the document
let layers: PdfLayerCollection = document.layers;
// Add a new layer to the document with the name 'Layer1' and set visibility to be true
let layer: PdfLayer = layers.add('Layer1', true);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| name | string |
Name of the layer. |
| visible | boolean |
Visibility of the layer. |
Returns PdfLayer
at
Gets the PdfLayer at the specified index.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the collection of layers in the document
let layers: PdfLayerCollection = document.layers;
// Retrieve the first layer from the layers collection
let layer: PdfLayer = layers.at(0);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| index | number |
Layer index. |
Returns PdfLayer
clear
Remove all the layers.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the collection of layers in the document
let layers: PdfLayerCollection = document.layers;
// Removes all layers from the collection
layers.clear();
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Returns void
contains
Boolean indicating whether the specified layer exists or not.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the collection of layers in the document
let layers: PdfLayerCollection = document.layers;
// Add a new layer to the document with the name 'Layer1'
let layer: PdfLayer = layers.add('Layer1');
// Check if the layer is present in the layers collection
let isPresent: boolean = layers.contains(layer);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| layer | PdfLayer |
The layer to be checked. |
Returns boolean
contains
Boolean indicating whether the specified layer name exists or not.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the collection of layers in the document
let layers: PdfLayerCollection = document.layers;
// Add a new layer to the document with the name 'Layer1'
let layer: PdfLayer = layers.add('Layer1');
// Check if the layer is present in the layers collection
let isPresent: boolean = layers.contains('Layer1');
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| name | string |
The layer name to be checked. |
Returns boolean
indexOf
Index of the specified layer.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the collection of layers in the document
let layers: PdfLayerCollection = document.layers;
// Add a new layer to the document with the name 'Layer1'
let layer: PdfLayer = layers.add('Layer1');
// Find the index of the layer in the layers collection
let index: number = layers.indexOf(layer);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| layer | PdfLayer |
The layer to be checked. |
Returns number
move
Move the PdfLayer into the collection at specified index.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the collection of layers in the document
let layers: PdfLayerCollection = document.layers;
// Add a new layer to the document with the name 'Layer1'
let layer: PdfLayer = layers.add('Layer1');
// Add a new layer to the document with the name 'Layer2'
let layer1: PdfLayer = layers.add('Layer2');
// Move 'layer2' to the first position (index 0)
layers.move(0, layer2);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| index | number |
Index of the layer. |
| layer | PdfLayer |
Layer to move. |
Returns void
remove
Remove the PdfLayer with layer instance from the collection.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the collection of layers in the document
let layers: PdfLayerCollection = document.layers;
// Add a new layer to the document with the name 'Layer1'
let layer: PdfLayer = layers.add('Layer1');
// Remove the layer from layer collection with instance
layers.remove(layer);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| layer | PdfLayer |
Layer to remove. |
Returns void
remove
Remove the PdfLayer with layer instance from the collection.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the collection of layers in the document
let layers: PdfLayerCollection = document.layers;
// Add a new layer to the document with the name 'Layer1'
let layer: PdfLayer = layers.add('Layer1');
// Remove the layer from layer collection with instance and graphics on page
layers.remove(layer, true);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| layer | PdfLayer |
Layer to remove. |
| removeGraphicalContent | boolean |
Remove graphical content, if true. |
Returns void
remove
Remove the PdfLayer at the layer name from the collection.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the collection of layers in the document
let layers: PdfLayerCollection = document.layers;
// Add a new layer to the document with the name 'Layer1'
let layer: PdfLayer = layers.add('Layer1');
// Remove the layer with name
layers.remove('Layer1');
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| name | string |
Layer name to remove. |
Returns void
remove
Remove the PdfLayer at the layer name from the collection.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the collection of layers in the document
let layers: PdfLayerCollection = document.layers;
// Add a new layer to the document with the name 'Layer1'
let layer: PdfLayer = layers.add('Layer1');
// Remove the layer with name and graphics on page
layers.remove('Layer1', true);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| name | string |
Layer name to remove. |
| removeGraphicalContent | boolean |
Remove graphical content, if true. |
Returns void
removeAt
Remove the PdfLayer at the specified index from the collection.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the collection of layers in the document
let layers: PdfLayerCollection = document.layers;
// Remove the layer at index 0 (the first layer)
layers.removeAt(0);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| index | number |
The index of the layer to be removed. |
Returns void
removeAt
Remove the PdfLayer at the specified index from the collection.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Access the collection of layers in the document
let layers: PdfLayerCollection = document.layers;
// Remove the layer at index 0 (the first layer) with graphics on page
layers.removeAt(0, true);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| index | number |
The index of the layer to be removed. |
| removeGraphicalContent | boolean |
Remove graphical content, if true. |
Returns void