How can I help you?
PdfForm
21 Apr 20267 minutes to read
Represents a PDF form.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the form of the PDF document
let form: PdfForm = document.form;
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Properties
Get count number
Gets the fields count (Read only).
Get exportEmptyFields boolean
Gets a value indicating whether allow to export empty fields or not.
Set exportEmptyFields void
Sets a value indicating whether allow to export empty fields or not.
| Parameter | Type | Description |
|---|---|---|
| value | boolean |
Export empty fields. |
Get fieldAutoNaming boolean
Gets a value indicating whether the automatic field naming is enabled for form fields.
Set fieldAutoNaming void
Sets a value indicating whether field auto-naming is enabled for form fields.
| Parameter | Type | Description |
|---|---|---|
| value | boolean |
Enable or disable field auto naming. The default value is false. |
Get needAppearances boolean
Gets a value indicating whether need appearances (Read only).
Methods
add
Add a new PdfField.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Add a new form field
let index: number = document.form.add(field);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| field | PdfField |
Field object to add. |
Returns number
fieldAt
Gets the PdfField at the specified index.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the loaded form field
let field: PdfField = document.form.fieldAt(0);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| index | number |
Field index. |
Returns PdfField
orderFormFields
Order the form fields.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Order the form fields.
document.form.orderFormFields();
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();Returns void
orderFormFields
Order the form fields based on page tab order.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Order the form fields based on page tab order.
document.form.orderFormFields(PdfFormFieldsTabOrder.row);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| tabOrder | PdfFormFieldsTabOrder |
tab order types for form fields. |
Returns void
orderFormFields
Order the form fields based on tab collection.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
//Set the tab collection to order the form fields.
let values: Map<number, PdfFormFieldsTabOrder> = new Map<number, PdfFormFieldsTabOrder>();
// Set the tab order for the page index 1.
values.set(1, PdfFormFieldsTabOrder.column);
// Set the tab order for the page index 2.
values.set(2, PdfFormFieldsTabOrder.row);
// Order the form fields based on tab collection.
document.form.orderFormFields(values);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| tabCollection | Map |
collection of tab order with page index. |
Returns void
removeField
Remove the specified PDF form field.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the loaded form field
let field: PdfField = document.form.fieldAt(3);
// Remove the form field
document.form.removeField(field);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| field | PdfField |
Field object to remove. |
Returns void
removeFieldAt
Remove the PDF form field from specified index.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Remove the form field from the specified index
document.form.removeFieldAt(3);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| index | number |
Field index to remove. |
Returns void
setDefaultAppearance
Sets the flag to indicate the new appearance creation
If true, appearance will not be created. Default appearance has been considered.
If false, new appearance stream has been created from field values and updated as normal appearance.
// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Set boolean flag to create a new appearance stream for form fields.
document.form.setDefaultAppearance(false);
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();| Parameter | Type | Description |
|---|---|---|
| value | boolean |
Set default appearance. |
Returns void