I have a PDF which has 5 text fields with the same field name "BankNameSingle"
When I use Delphi 7 and QuickPDF version 16.x and loop through the fields and log the field names in the PDF here is my code:
// Loop through fields and display the field Names fieldCount := PDF.FormFieldCount ; for FieldIX := 1 to fieldCount do begin Log( PDF.GetFormFieldTitle(FieldIX) ); childCount := PDF.GetFormFieldKidCount(FieldIX) ; if (childCount > 0) then begin for childIX := 1 to childCount do begin tempIX := pdf.GetFormFieldKidTempIndex(FieldIX, childIX) ; Log(' '+PDF.GetFormFieldTitle(tempIX)); end ; end ; end ;
And here is what it outputs:
BankNameSingle. BankNameSingle. BankNameSingle. BankNameSingle. BankNameSingle. BankNameSingle BankNameSingle.1 BankNameSingle.2 BankNameSingle.3 BankNameSingle.4 BankNameSingle.5
First Question is why do the 5 child fields seem to have a corresponding (I'm not sure what to call it), main field with the period at the end? So clearly the field with no period at the end is the parent then the ones indented with a period plus the number 1 thru 5 are the child fields, but what do I do with the fields that are not the parent and not the child either?
Second Part is I have no idea how to set the "Value" to the fields. I have a test program to set the fields value, save the pdf to disk then I open the PDF. In almost all cases the value only shows in the first field encountered and not the other fields.
I have tried setting the value to just the parent. I have tried setting the value to just the child fields. And I have tried setting the value for both the Parent and the Child Fields. I am ignoring the fields that just end with the period. Below is sample code for setting value to both the parent and child fields.
myTestObj.UpdateFieldValue('BankNameSingle', 'Bank Name Goes Here') ;
.... procedure TTestObject.UpdateFieldValue(FieldName: String; Value: String) ;
fieldCount := PDF.FormFieldCount ; for FieldIX := 1 to fieldCount do begin if (PDF.GetFormFieldTitle(FieldIX) = FieldName) then begin PDF.SetFormFieldValue(FieldIX, Value) ; PDF.SetFormFieldDefaultValue(FieldIX, Value) ; childCount := PDF.GetFormFieldKidCount(FieldIX) ; if (childCount > 0) then begin for childIX := 1 to childCount do begin tempIX := pdf.GetFormFieldKidTempIndex(FieldIX, childIX) ; PDF.SetFormFieldValue(tempIX, Value) ; PDF.SetFormFieldDefaultValue(tempIX, Value) ; end ; end ; end ; end ;
end ;
I have traced through the code and it is calling SetFormFieldValue() and SetFormFieldDefaultValue() when I want it to but the output is not all fields have the value. By the way I can open the PDF with FoxIt and type any value in any one of those 5 fields and what I type will also be updated in all of the other 4 fields with that name. So it works as expected in FoxIt Reader.
Any help would be greatly appreciated.
|