@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
638 lines (637 loc) • 21.7 kB
TypeScript
import { PdfDocument } from '../pdf-document';
import { PdfLayer } from './layer';
/**
* The class provides methods and properties to handle the collection of `PdfLayer`.
* ```typescript
* // 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();
* ```
*/
export declare class PdfLayerCollection {
/**
* Whether this collection represents sub-layers.
*
* @private
* @type {boolean}
*/
_subLayer: boolean;
/**
* Internal flag indicating whether resources for layers are present.
*
* @private
* @type {boolean}
*/
private _isLayerContainsResource;
/**
* Document that owns this collection.
*
* @private
* @type {PdfDocument}
*/
private _document;
/**
* Parent layer when this collection represents sublayers.
*
* @private
* @type {PdfLayer}
*/
private _parent;
/**
* Map from reference to PdfLayer for quick lookup.
*
* @private
* @type {Map<_PdfReference, PdfLayer>}
*/
private _layerDictionary;
/**
* Internal counter used when processing BDC/EMC markers.
*
* @private
* @type {number}
*/
private _bdcCount;
/**
* Internal ordered list of layers.
*
* @private
* @type {PdfLayer[]}
*/
private _list;
/**
* Cross-reference used for object resolution.
*
* @private
* @type {_PdfCrossReference}
*/
private _crossReference;
/**
* Catalog associated with the document.
*
* @private
* @type {_PdfCatalog}
*/
private _catalog;
/**
* Initializes a new instance of the `PdfLayerCollection` class with document.
*
* @private
* @param {PdfDocument} document Document.
*/
constructor(document: PdfDocument);
/**
* Initializes a new instance of the `PdfLayerCollection` class with document and layer.
*
* @private
* @param {PdfDocument} document Document.
* @param {PdfLayer} layer PDF layer.
*/
constructor(document: PdfDocument, layer: PdfLayer);
/**
* Gets the value indicating whether the skip state is active for the internal element.
*
* @private
* @returns {boolean} True if the current BDC count is greater than zero; otherwise, false.
*/
readonly _isSkip: boolean;
/**
* Gets the layer count.
*
* @returns {number} Number of layers.
*
* ```typescript
* // 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 layer counts from the layers collection
* let count: number = layers.count;
* // Save the document
* document.save('output.pdf');
* // Destroy the document
* document.destroy();
* ```
*/
readonly count: number;
/**
* Gets the `PdfLayer` at the specified index.
*
* ```typescript
* // 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();
* ```
*
* @param {number} index Layer index.
* @returns {PdfLayer} Layer at the specified index.
*/
at(index: number): PdfLayer;
/**
* Create a new `PdfLayer` with name
* add it to the end of the collection.
*
* ```typescript
* // 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();
* ```
*
* @param {string} name Name of the layer.
* @returns {PdfLayer} Layer with the name specified.
*/
add(name: string): PdfLayer;
/**
* Create a new `PdfLayer` with name and Boolean flag to set the visibility of layer
* add it to the end of the collection.
*
* ```typescript
* // 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();
* ```
*
* @param {string} name Name of the layer.
* @param {boolean} visible Visibility of the layer.
* @returns {PdfLayer} Layer with the name specified.
*/
add(name: string, visible: boolean): PdfLayer;
/**
* Boolean indicating whether the specified layer exists or not.
*
* ```typescript
* // 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();
* ```
*
* @param {PdfLayer} layer The layer to be checked.
* @returns {boolean} Returns true, if the layer exists. Otherwise, false
*/
contains(layer: PdfLayer): boolean;
/**
* Boolean indicating whether the specified layer name exists or not.
*
* ```typescript
* // 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();
* ```
*
* @param {string} name The layer name to be checked.
* @returns {boolean} Returns true, if the layer exists. Otherwise, false
*/
contains(name: string): boolean;
/**
* Remove all the layers.
*
* ```typescript
* // 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} Returns nothing.
*/
clear(): void;
/**
* Index of the specified layer.
*
* ```typescript
* // 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();
* ```
*
* @param {PdfLayer} layer The layer to be checked.
* @returns {number} Index of the layer.
*/
indexOf(layer: PdfLayer): number;
/**
* Move the `PdfLayer` into the collection at specified index.
*
* ```typescript
* // 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();
* ```
*
* @param {number} index Index of the layer.
* @param {PdfLayer} layer Layer to move.
* @returns {void} Returns nothing.
*/
move(index: number, layer: PdfLayer): void;
/**
* Remove the `PdfLayer` at the specified index from the collection.
*
* ```typescript
* // 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();
* ```
*
* @param {number} index The index of the layer to be removed.
* @returns {void} Returns nothing.
*/
removeAt(index: number): void;
/**
* Remove the `PdfLayer` at the specified index from the collection.
*
* ```typescript
* // 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();
* ```
*
* @param {number} index The index of the layer to be removed.
* @param {boolean} removeGraphicalContent Remove graphical content, if true.
* @returns {void} Returns nothing.
*/
removeAt(index: number, removeGraphicalContent: boolean): void;
/**
* Remove the `PdfLayer` with layer instance from the collection.
*
* ```typescript
* // 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();
* ```
*
* @param {PdfLayer} layer Layer to remove.
* @returns {void} Returns nothing.
*/
remove(layer: PdfLayer): void;
/**
* Remove the `PdfLayer` with layer instance from the collection.
*
* ```typescript
* // 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();
* ```
*
* @param {PdfLayer} layer Layer to remove.
* @param {boolean} removeGraphicalContent Remove graphical content, if true.
* @returns {void} Returns nothing.
*/
remove(layer: PdfLayer, removeGraphicalContent: boolean): void;
/**
* Remove the `PdfLayer` at the layer name from the collection.
*
* ```typescript
* // 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();
* ```
*
* @param {string} name Layer name to remove.
* @returns {void} Returns nothing.
*/
remove(name: string): void;
/**
* Remove the `PdfLayer` at the layer name from the collection.
*
* ```typescript
* // 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();
* ```
*
* @param {string} name Layer name to remove.
* @param {boolean} removeGraphicalContent Remove graphical content, if true.
* @returns {void} Returns nothing.
*/
remove(name: string, removeGraphicalContent: boolean): void;
/**
* Reads print state from a dictionary and applies it to the layer.
*
* @private
* @param {_PdfDictionary} printOption The print option dictionary.
* @param {PdfLayer} layer The target layer.
* @returns {void} nothing.
*/
private _setPrintState;
/**
* Adds a layer to the internal list and creates backend objects if required.
*
* @private
* @param {PdfLayer} layer The layer to add.
* @returns {number} The index of the added layer.
*/
private _addLayer;
/**
* Creates PDF objects for a layer and updates document OCProperties.
*
* @private
* @param {PdfLayer} layer The layer to create.
* @returns {void} nothing.
*/
private _createLayer;
/**
* Creates the optional content dictionary entries for a layer.
*
* @private
* @param {PdfLayer} layer The layer to create the dictionary for.
* @returns {Array<_PdfReference>} Array of references added.
*/
private _createOptionalContentDictionary;
/**
* Builds the optional content views dictionary for the document.
*
* @private
* @returns {_PdfDictionary} The created views dictionary.
*/
private _createOptionalContentViews;
/**
* Creates and links print option dictionaries for the specified layer.
*
* @private
* @param {PdfLayer} layer The layer to create print options for.
* @returns {_PdfReference} Reference to the created usage dictionary.
*/
private _setPrintOption;
/**
* Registers a sublayer and updates document ordering structures.
*
* @private
* @param {_PdfDictionary} ocProperties The OCProperties dictionary.
* @param {_PdfReference} reference The reference for the layer.
* @param {PdfLayer} layer The layer instance.
* @returns {void} nothing.
*/
private _createSublayer;
/**
* Applies locked state to layers based on OCProperties.
*
* @private
* @param {_PdfDictionary} ocProperties The OCProperties dictionary.
* @returns {void} nothing.
*/
private _checkLayerLock;
/**
* Updates visibility of layers based on OCProperties 'OFF' list.
*
* @private
* @param {_PdfDictionary} ocProperties The OCProperties dictionary.
* @returns {void} nothing.
*/
private _checkLayerVisible;
/**
* Parses parent/child relationships for layers from OCProperties.
*
* @private
* @param {_PdfDictionary} ocProperties The OCProperties dictionary.
* @returns {void} nothing.
*/
private _checkParentLayer;
/**
* Recursively parses a layer order array to build parent-child relationships.
*
* @private
* @param {PdfLayer} parent The parent layer in recursion.
* @param {(_PdfReference | _PdfReference[])[]} array The order array.
* @param {Map<_PdfReference, PdfLayer>} layerDictionary Map of references to layers.
* @returns {void} nothing.
*/
private _parsingLayerOrder;
/**
* Reorders internal list to reflect hierarchical layer order from OCProperties.
*
* @private
* @param {_PdfDictionary} ocProperties The OCProperties dictionary.
* @returns {void} nothing.
*/
private _createLayerHierarchical;
/**
* Adds child layers of a parent into the parent's `layers` collection.
*
* @private
* @param {PdfLayer} layer Parent layer whose children will be added.
* @returns {void} nothing.
*/
private _addChildLayer;
/**
* Adds a nested layer into the internal list without creating resources.
*
* @private
* @param {PdfLayer} layer The nested layer to add.
* @returns {number} The index of the added nested layer.
*/
private _addNestedLayer;
/**
* Removes a layer and associated metadata from the document catalog.
*
* @private
* @param {PdfLayer} layer The layer to remove.
* @param {boolean} removeGraphicalContent Whether to remove graphical content.
* @returns {void} nothing.
*/
private _removeLayer;
/**
* Removes a layer reference from the OCG group array.
*
* @private
* @param {PdfLayer} layer The layer to remove.
* @param {_PdfReference[]} ocGroup The OCG reference array.
* @returns {void} nothing.
*/
private _removeOCG;
/**
* Removes usage references for a layer from usage dictionaries.
*
* @private
* @param {PdfLayer} layer The target layer.
* @param {_PdfReference[]} _usage Array of usage references.
* @returns {void} nothing.
*/
private _removeUsage;
/**
* Removes references to a layer from order arrays recursively.
*
* @private
* @param {PdfLayer} layer The layer to remove.
* @param {(_PdfReference[] | _PdfReference)[]} order The order array to update.
* @param {(_PdfReference | _PdfReference[])[]} arrayList Helper array used during recursion.
* @returns {void} nothing.
*/
private _removeOrder;
/**
* Removes layer reference from ON/OFF visibility arrays.
*
* @private
* @param {PdfLayer} layer The layer to remove.
* @param {_PdfReference[]} on ON references array.
* @param {_PdfReference[]} off OFF references array.
* @returns {void} nothing.
*/
private _removeVisible;
/**
* Removes layer reference from locked array.
*
* @private
* @param {PdfLayer} layer The layer to remove.
* @param {_PdfReference[]} locked Locked references array.
* @returns {void} nothing.
*/
private _removeLocked;
/**
* Removes graphical content associated with a layer from pages.
*
* @private
* @param {PdfLayer} layer The layer whose content should be removed.
* @returns {void} nothing.
*/
private _removeLayerContent;
/**
* Processes begin marked content operators and filters out layer content.
*
* @private
* @param {PdfLayer} parser The parser/layer instance.
* @param {string} operator The content operator.
* @param {string[]} operands Operator operands.
* @param {_PdfContentStream} data Output content stream.
* @param {string} [id] Optional object id string.
* @returns {void} nothing.
*/
private _processBeginMarkContent;
/**
* Writes an operator and its operands into a content stream, optionally skipping.
*
* @private
* @param {string[]} operands The operands to write.
* @param {string} operator The operator to write.
* @param {boolean} skip Whether writing should be skipped based on state.
* @param {_PdfContentStream} data The target content stream.
* @returns {void} nothing.
*/
private _streamWrite;
/**
* Inserts a layer reference into the document order at the specified index.
*
* @private
* @param {number} index The insertion index.
* @param {PdfLayer} layer The layer to insert.
* @returns {void} nothing.
*/
private _insertLayer;
}