Overview and notes
When form field mode is enabled, the user can edit form fields in the document. Filling out form fields only works for PDF documents.
The following elements are supported:
-
Text box
-
Checkbox.
-
Radio button.
-
Drop-down list
-
Combobox
Signature fields cannot be edited with this component. For digital signatures, you can use the signotec component SignPDF3.
Changes made in form field mode can be applied using the SaveDocument method.
When you save the changes, the entire document is rewritten and any signatures that have already been entered become invalid. It is therefore recommended that only unsigned documents are edited. The component does not indicate if signatures may have lost their validity.
Form field mode can be activated and deactivated using the corresponding button in the toolbar or the EnablePDFFormularMode function.
Deactivating form field mode also causes the document to be saved at the same time by overwriting, provided that it was loaded via LoadDocument.
If you want to prevent users from changing the form field mode, you can hide the toolbar.
While form mode is active, the use of other methods may be limited or not possible. Equally, some functions in the component’s toolbar are deactivated (e.g. printing). Highlighting regions by means of SetSelection or AllowMouseSelection is not possible. Instead, you can use SetHighlightFields to highlight form fields.
Form fields in PDF documents can be restricted to the input of particular data types. This makes it possible to specify that only data with a particular syntax can be entered in a form field, for example, or that a field can accept numbers but not letters. This syntax check of the form field data is performed by JavaScript.
The following JavaScript commands for syntax checking of the form field data are supported by this component:
-
AFDate_FormatEx (formatting as date)
-
AFNumber_Format (formatting as a number)
Examples of formatting in PDF:
AFDate_FormatEx("ddmmyyyy");
AFDate_FormatEx("mm");
AFDate_FormatEx("d mmmm, yyyy");
AFNumber_Format(0, 3, 0, 0, "", false);
AFNumber_Format(2, 2, 0, 0, "", false);
EnablePDFFormularMode method
This method can be used to activate and deactivate form mode for actively filling out PDF documents. This mode is disabled by default.
The return value of this method corresponds to the PDFFormularMode property at the time of the call.
Depending on the input parameters, the document may be saved automatically if it was loaded with LoadDocument.
Please also note the general information on form field mode!
int EnablePDFFormularMode(int nOptions);
long EnablePDFFormularMode(long nOptions);
|
Parameter
|
In |
Out |
Possible Values |
Description |
|---|---|---|---|---|
|
nOptions |
✔️ |
|
0 |
Deactivate form field mode If the mode was activated and the document was loaded via LoadDocument, it is saved The button for changing the mode in the toolbar is deactivated |
|
1 |
Activate form field mode The button for changing the mode in the toolbar is activated |
|||
|
2 |
The button for changing the mode in the toolbar is activated |
|
Return value |
Description |
|---|---|
|
0 |
Form field mode is currently turned off |
|
1 |
Form field mode is currently turned on |
SetHighlightFields method
This method changes the visual appearance of form fields in form field mode. Changes can be made even if a PDF document has not been loaded.
int SetHighlightFields(short nMode);
long SetHighlightFields(short nMode);
|
Parameter
|
In |
Out |
Possible Values |
Description |
|---|---|---|---|---|
|
nMode |
✔️ |
|
0 |
No colour background (default) |
|
1 |
Colour highlighting for form fields |
|
Return value |
Description |
|---|---|
|
0 |
An error has occurred |
|
1 |
Method was executed successfully |
SetRenderInternal method
This method can be used to set whether the tab key can be used to navigate between form fields while form field mode is active.
sbyte SetRenderInternal(int nOptions);
char SetRenderInternal(long nOptions);
|
Parameter
|
In |
Out |
Possible Values |
Description |
|---|---|---|---|---|
|
nOptions |
✔️ |
|
1 |
Tab stops are not interpreted (default) |
|
1000 |
Tab stops are interpreted |
|
Return value |
Description |
|---|---|
|
0 |
An error has occurred |
|
1 |
Method was executed successfully |
IsModified method
This method returns whether a PDF document was changed in form field mode.
int IsModified();
long IsModified();
|
Return value |
Description |
|---|---|
|
0 |
The document has not been modified |
|
1 |
The document has been modified |
GetEmptyMandatoryField method
This method searches for empty editable required form fields in a PDF document. This allows you to check whether there are any mandatory fields that have not yet been filled in. It can return the number of unfilled mandatory fields or the index of such a field in the internal list of form fields. (If the PDF form field index is required instead, it can be queried afterwards with MapFieldIndex2PDFIndex.)
To jump directly to a field in the display that has not yet been filled in, use the SelectFormfield method.
Please note the general information on form field mode, especially regarding saving changes.
int GetEmptyMandatoryField(int nOption);
long GetEmptyMandatoryField(long nOption);
|
Parameter
|
In |
Out |
Possible values |
Description |
|---|---|---|---|---|
|
nOption |
✔️ |
|
>=0 |
Index in the list of unfilled mandatory fields; the total index of the corresponding field is returned |
|
-1 |
The number of unfilled mandatory fields is returned |
|
Return value |
Description |
|---|---|
|
>= 0 |
Either the index of the requested mandatory form field or the total number of unfilled mandatory form fields found (see nOption) |
|
-1 |
No PDF document has been loaded, form field mode is enabled, or the requested mandatory field does not exist |
Code example for finding all unfilled mandatory fields:
int requiredCount = axSTImgCtl1.GetEmptyMandatoryField(-1);
if (requiredCount > 0)
{
List<int> requiredIndices = new List<int>();
for (int i = 0; i < requiredCount; i++)
{
requiredIndices.Add(axSTImgCtl1.GetEmptyMandatoryField(i));
}
}
Code example for testing whether there are any mandatory fields that have not been filled in:
if (axSTImgCtl1.GetEmptyMandatoryField(0) >=0)
{
MessageBox.Show("Es liegen unausgefüllte Pflichtfelder vor!");
}
GetEmptyOptionalField method
This method searches for empty editable optional form fields in a PDF document. This allows you to check whether there are any optional fields that have not yet been filled in. The number of unfilled optional fields can be returned, or the index of such a field in the internal list of form fields. (If the PDF form field index is required instead, it can be queried afterwards with MapFieldIndex2PDFIndex.)
To jump directly to a field in the display that has not yet been filled in, use the SelectFormfield method.
Please note the general information on form field mode, especially regarding saving changes.
int GetEmptyOptionaField(int nReserved);
long GetEmptyOptionaField(long nReserved);
|
Parameter
|
In |
Out |
Possible values |
Description |
|---|---|---|---|---|
|
nOption |
✔️ |
|
>=0 |
Index in the list of unfilled optional fields; the total index of the corresponding field is returned |
|
-1 |
The number of unfilled optional fields is returned |
|
Return value |
Description |
|---|---|
|
>= 0 |
Either the index of the requested optional form field or the total number of unfilled optional form fields found (see nOption) |
|
-1 |
No PDF document has been loaded, form field mode is enabled, or the requested unfilled optional field does not exist |
For a code example, see the GetEmptyMandatoryField method, which is applied in an equivalent manner.
SelectFormfield method
This method sets the focus of the display to the desired form field element. To do this, the position index of the field in the internal list of form fields must be transferred, which can be obtained from the methods GetEmptyMandatoryField and GetEmptyOptionalField.
int SelectFormfield(int nIndex, int nReserved);
long SelectFormfield(long nIndex, long nReserved);
|
Parameter
|
In |
Out |
Possible Values |
Description |
|---|---|---|---|---|
|
nIndex |
✔️ |
|
>=0 |
Index of the desired form field element; must be less than the total number of form fields |
|
nReserved |
✔️ |
|
0 |
Reserved |
|
Return value |
Description |
|
|---|---|---|
|
1 |
Method was executed successfully |
|
|
<= 0 |
An error has occurred |
|
|
|
-1 |
The document is not a PDF |
|
|
-2 |
One of the parameters contains an invalid value or no document is currently displayed |
MapFieldIndex2PDFIndex method
This method is used to acquire the index of a field in the currently opened PDF document as a PDF-compatible field index. This requires the internal field index, which is provided by the methods GetEmptyMandatoryField and GetEmptyOptionalField.
int MapFieldIndex2PDFIndex(int nIndex);
long MapFieldIndex2PDFIndex(long nIndex);
|
Parameter
|
In |
Out |
Possible Values |
Description |
|---|---|---|---|---|
|
nIndex |
✔️ |
|
0 |
Internal field index; must be less than the total number of form fields |
|
Return value |
Description |
|
|---|---|---|
|
>=0 |
Method executed successfully, return value corresponds to PDF field index |
|
|
< 0 |
An error has occurred |
|
|
|
-1 |
The loaded document is not a PDF |
|
|
-2 |
One of the parameters contains an invalid value or no document is currently displayed |
|
|
-4 |
The selected index does not exist |
PDFFormularMode property
This property can be used to query the form field mode status.
int PDFFormularMode;
long PDFFormularMode;
|
In |
Out |
Possible Values |
Description |
|---|---|---|---|
|
|
✔️ |
0 |
Form field mode is deactivated |
|
1 |
Form field mode is activated |
PDFTotalFormularFields property
This property can be used to query the number of form fields in the loaded document that can be edited by means of the form field mode.
int PDFTotalFormularFields;
long PDFTotalFormularFields;
|
In |
Out |
Possible Values |
Description |
|---|---|---|---|
|
|
✔️ |
>=0 |
Number of form fields. |
FormFieldClicked event
This event signals that a form field button has been clicked with the mouse or that the text in a text field has changed. Form field mode must be active for this. The type of form field, its index position and its subindex are returned in PDF-compatible format. Signature fields are ignored by this event.
The following shows an example implementation in which user-defined names have been replaced by placeholders (%…%).
public class _DSTImgCtlEvents_FormFieldClickedEvent
{
public int nType;
public int nIndex;
public int nSubIndex;
public _DSTImgCtlEvents_FormFieldClickedEvent(int nType, int nIndex, int nSubIndex)
{
this.nType = nType;
this.nIndex = nIndex;
this.nSubIndex = nSubIndex;
}
}
this.%COMPONENT_NAME%.FormFieldClicked += new AxSTIMGCTLLib._DSTImgCtlEvents_FormFieldClickedEventHandler(this.%CALLBACK_FUNCTION%);
private void %CALLBACK_FUNCTION%(object sender, AxSTIMGCTLLib._DSTImgCtlEvents_FormFieldClickedEvent e);
BEGIN_EVENTSINK_MAP(%CLASS_NAME%, CDialogEx)
ON_EVENT(%CLASS_NAME%, %COMPONENT_ID%, 4, %CALLBACK_FUNCTION%, VTS_I4 VTS_I4 VTS_I4)
END_EVENTSINK_MAP()
void %CALLBACK_FUNCTION%(long nType, long nIndex, long nSubIndex);
|
Parameter |
Possible values |
Description |
|---|---|---|
|
nType |
0 |
Unknown |
|
1 |
Text box |
|
|
3 |
Checkbox |
|
|
4 |
Radio button |
|
|
5 |
List box / combo box |
|
|
nIndex |
>=0 |
Position |
|
nSubIndex |
>=0 |
SubIndex (if available) |
Event FormFieldTouched event
This event signals that a form field button has been clicked with the mouse. Neither form field mode nor mouse selection (see AllowMouseSelection) may be active for this. The type of form field, its index position and its subindex are returned in PDF-compatible format. Signature fields are ignored by this event.
The following shows an example implementation in which user-defined names have been replaced by placeholders (%…%).
public class _DSTImgCtlEvents_FormFieldTouchedEvent
{
public int nType;
public int nIndex;
public int nSubIndex;
public _DSTImgCtlEvents_FormFieldTouchedEvent(int nType, int nIndex, int nSubIndex)
{
this.nType = nType;
this.nIndex = nIndex;
this.nSubIndex = nSubIndex;
}
}
this.%COMPONENT_NAME%.FormFieldTouched += new AxSTIMGCTLLib._DSTImgCtlEvents_FormFieldTouchedEventHandler(this.%CALLBACK_FUNCTION%);
private void %CALLBACK_FUNCTION%(object sender, AxSTIMGCTLLib._DSTImgCtlEvents_MarkEndEvent e);
BEGIN_EVENTSINK_MAP(%CLASS_NAME%, CDialogEx)
ON_EVENT(%CLASS_NAME%, %COMPONENT_ID%, 5, %CALLBACK_FUNCTION%, VTS_I4 VTS_I4 VTS_I4)
END_EVENTSINK_MAP()
void %CALLBACK_FUNCTION%(long nType, long nIndex, long nSubIndex);
|
Parameter |
Possible values |
Description |
|---|---|---|
|
nType |
0 |
Unknown |
|
1 |
Text box |
|
|
3 |
Checkbox |
|
|
4 |
Radio button |
|
|
5 |
List box / combo box |
|
|
nIndex |
>=0 |
Position |
|
nSubIndex |
>=0 |
SubIndex (if available) |