3.7 Form
Form APIs enable viewing, creating and editing interactive form fields in a PDF document, making form data collection easy and simple. Please note ZSForm_Load or ZSDoc_CreateForm needs to be called before using other functions in the Form module. You can use ZSDoc_HasForm to check if the PDF document has an AcroForm. Here are some common APIs for form processing listed in Table 3.8. For a complete list of APIs, please refer to ZSForm.h.
Table 3.8
|
API Name |
Description |
1 |
ZSForm_Load |
Retrieve a form handle for a specific document. |
2 |
ZSDoc_CreateForm |
Create an AcroForm. |
3 |
ZSForm_Release |
Release a PDF interactive form object. |
4 |
ZSForm_GetDocument |
Retrieve a PDF document which contains the form. |
5 |
ZSForm_GetDefaultAppearance |
Retrieve a default form appearance. |
6 |
ZSForm_NumFields |
Get a count of interactive fields in a form. |
7 |
ZSForm_AddField |
Add a form field to AcroForm, and also create a new form control with the field. |
8 |
ZSField_GetAction |
Get the action associated with a certain field in a form. |
9 |
ZSField_GetOptions |
Get list box or combo box options. |
10 |
ZSField_SetDefaultValue |
Set default value of the field (except signature field). |
This is an example of how to count interactive form fields and get the form properties.
Example: Count interactive form fields and get form properties.
ZSInt32 fieldCount = 0;
ZSInt32 fieldType = 0;
ZSInt32 alignment = 0;
ZSBStr fieldname;
ZSBStr_Init(&fieldName);
ZSForm form = NULL;
ret = ZSForm_Load(doc, &form);
ZSForm_NumFields(form, &fieldCount);
for (int i = 0; i < fielCount; i++)
{
ret = ZSForm_GetField(form, i, &fieldname, &fieldType);
if (ZS_OK == ret)
{
if (ZSFORM_FIELD_CHECKBOX == fieldType)
{
//do something
}
ret = ZSField_GetAlignment(form, &fieldname, &alignment);
{
}
|