Pdf - PdfHideTargetCollection
18 Nov 202611 minutes to read
Represents a collection of form-field and annotation targets associated with a PDF Hide Action.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
let page: PdfPage = document.addPage();
// Create a Hide Action
let action: PdfHideAction = new PdfHideAction(true);
// Add targets to the collection
action.targets.add({ fieldName: 'CustomerName' });
// Get the target count
let count: number = action.targets.count;
// Read a target
let target: PdfHideTarget = action.targets.itemAt(0);
// Remove a target
action.targets.removeAt(0);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Properties
Get count number
Gets the number of targets in the collection.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Get the first page
let page: PdfPage = document.getPage(0) as PdfPage;
// Get the form field
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the Hide Action
let action: PdfHideAction = field.actions.mouseUp as PdfHideAction;
// Get the target count
let count: number = action.targets.count;
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Methods
add
Adds the specified target to the end of the collection.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page
let page: PdfPage = document.addPage();
// Create button and text-box fields
let button: PdfButtonField = new PdfButtonField(page, 'button', {
x: 20, y: 20, width: 100, height: 30
});
let textBox: PdfTextBoxField = new PdfTextBoxField(page, 'CustomerName', {
x: 20, y: 70, width: 150, height: 30
});
// Add the fields to the document
document.form.add(button);
document.form.add(textBox);
// Create a Hide Action
let action: PdfHideAction = new PdfHideAction(true);
// Add a field target
action.targets.add({ fieldName: 'CustomerName' });
// Assign the action to the button field
button.actions.mouseUp = action;
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| target | PdfHideTarget |
The target to add. |
Returns void
clear
Removes all targets from the collection.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page
let page: PdfPage = document.addPage();
// Create a button field
let button: PdfButtonField = new PdfButtonField(page, 'button', {
x: 20, y: 20, width: 100, height: 30
});
// Create a text-box field
let textBox: PdfTextBoxField = new PdfTextBoxField(page, 'CustomerName', {
x: 20, y: 70, width: 150, height: 30
});
// Add the fields to the document
document.form.add(button);
document.form.add(textBox);
// Create a Hide Action
let action: PdfHideAction = new PdfHideAction(true);
// Add a field target
action.targets.add({ fieldName: 'CustomerName' });
// Remove all targets
action.targets.clear();
// Assign the action to the button field
button.actions.mouseUp = action;
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Returns void
has
Determines whether the collection contains the specified target.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page
let page: PdfPage = document.addPage();
// Create a button field
let button: PdfButtonField = new PdfButtonField(page, 'button', {
x: 20, y: 20, width: 100, height: 30
});
// Create a text-box field
let textBox: PdfTextBoxField = new PdfTextBoxField(page, 'CustomerName', {
x: 20, y: 70, width: 150, height: 30
});
// Add the fields to the document
document.form.add(button);
document.form.add(textBox);
// Create a Hide Action
let action: PdfHideAction = new PdfHideAction(true);
// Add a field target
action.targets.add({ fieldName: 'CustomerName' });
// Check whether the target exists
let exists: boolean = action.targets.has({ fieldName: 'CustomerName' });
// Assign the action to the button field
button.actions.mouseUp = action;
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| target | PdfHideTarget |
The target to locate. |
Returns boolean
indexOf
Returns the zero-based index of the specified target, or -1 when it is not found.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page
let page: PdfPage = document.addPage();
// Create a button field
let button: PdfButtonField = new PdfButtonField(page, 'button', {
x: 20, y: 20, width: 100, height: 30
});
// Create a text-box field
let textBox: PdfTextBoxField = new PdfTextBoxField(page, 'CustomerName', {
x: 20, y: 70, width: 150, height: 30
});
// Add the fields to the document
document.form.add(button);
document.form.add(textBox);
// Create a Hide Action
let action: PdfHideAction = new PdfHideAction(true);
// Add a field target
action.targets.add({ fieldName: 'CustomerName' });
// Get the target index
let index: number = action.targets.indexOf({ fieldName: 'CustomerName' });
// Assign the action to the button field
button.actions.mouseUp = action;
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| target | PdfHideTarget |
The target to locate. |
Returns number
itemAt
Gets the target at the specified zero-based index.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data);
// Get the form field
let field: PdfButtonField = document.form.fieldAt(0) as PdfButtonField;
// Get the Hide Action
let action: PdfHideAction = field.actions.mouseUp as PdfHideAction;
// Get the first target
let target: PdfHideTarget = action.targets.itemAt(0);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| index | number |
The zero-based index of the target. |
Returns PdfHideTarget
remove
Removes the first matching target from the collection.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page
let page: PdfPage = document.addPage();
// Create a button field
let button: PdfButtonField = new PdfButtonField(page, 'button', {
x: 20, y: 20, width: 100, height: 30
});
// Create a text-box field
let textBox: PdfTextBoxField = new PdfTextBoxField(page, 'CustomerName', {
x: 20, y: 70, width: 150, height: 30
});
// Add the fields to the document
document.form.add(button);
document.form.add(textBox);
// Create a Hide Action
let action: PdfHideAction = new PdfHideAction(true);
// Add a field target
action.targets.add({ fieldName: 'CustomerName' });
// Remove the matching target
action.targets.remove({ fieldName: 'CustomerName' });
// Assign the action to the button field
button.actions.mouseUp = action;
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| target | PdfHideTarget |
The target to remove. |
Returns void
removeAt
Removes the target at the specified zero-based index.
// Create a new PDF document
let document: PdfDocument = new PdfDocument();
// Add a page
let page: PdfPage = document.addPage();
// Create a button field
let button: PdfButtonField = new PdfButtonField(page, 'button', {
x: 20, y: 20, width: 100, height: 30
});
// Add the button field to the document
document.form.add(button);
// Create a Hide Action
let action: PdfHideAction = new PdfHideAction(true);
// Add a field target
action.targets.add({ fieldName: 'CustomerName' });
// Remove the first target
action.targets.removeAt(0);
// Assign the action to the button field
button.actions.mouseUp = action;
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| index | number |
The zero-based index of the target to remove. |
Returns void