Do you own a Debenu Quick PDF Library 12/11/10/9/8/7? Upgrade to Debenu Quick PDF Library 13!

Foxit Quick PDF Library

Frequently Asked Question:

Return to FAQ Index

How does the FormFieldCount function work?

Question

How does the FormFieldCount function work?

Answer

The FormFieldCount function always returns the total number form fields in the document at the time the function is called. When FlattenFormField succeeds (returns 1) the field will be deleted from the PDF. This means that the field index of subsequent form fields will be reduced by 1. So the correct way to flatten the form fields is to keep a variable which is the current form field number and only increase it if the flattening fails.

Something like this:

Dim FieldIndex As Integer
Dim FieldCount As Integer
Dim LoopNumber As Integer

FieldCount = QP.FormFieldCount()
FieldIndex = 1

For LoopNumber = 1 to FieldCount
  If QP.FlattenFormField(FieldIndex) = 0 Then
    FieldIndex = FieldIndex + 1
  End If
Next

Or alternatively, another way to do it is like this:

Dim TotalFormFields As Integer 

QP.LoadFromFile(FileName);
TotalFormFields = PDFLibrary.FormFieldCount()

  While TotalFormFields > 0
    QP.FlattenFormField(TotalFormFields);
    TotalFormfields = TotalFormFields - 1;
  End While 

QP.SaveToFile(FileName);

© 2015 Debenu & Foxit. All rights reserved. AboutBuyContactBlogNewsletterSupportFAQProduct UpdatesForum