Print Page | Close Window

How to use Parent / Child Fields

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3702
Printed Date: 29 Apr 24 at 11:27AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: How to use Parent / Child Fields
Posted By: waynefulcher
Subject: How to use Parent / Child Fields
Date Posted: 29 Apr 19 at 10:45PM
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.







Replies:
Posted By: Ingo
Date Posted: 29 Apr 19 at 10:53PM
Hi Wayne,

this should give you an idea?
http://www.quickpdf.org/forum/setting-check-box-subfield-values_topic1842.html



-------------
Cheers,
Ingo



Posted By: waynefulcher
Date Posted: 30 Apr 19 at 1:14AM
I couldn't find anything relevant in that link. It only referred to setting the value for checkboxes and radiobutton which is a completely different topic.

But after a couple more hours of research I found a solution and figured I would post it for other developers.

When you are updating a fields value and want the PDF to show the new value especially when you have multiple text fields with the same name which creates child fields you should also call:
          PDF.UpdateAppearanceStream(Index);
right after calling the SetFormFieldValue();

There is also some notes about a NeedAppearances flag but I couldn't find notes that made sense as to how to set it and what the affects would be. But I do know if I call the UpdateAppearanceStream after setting the value then the output PDF shows correctly with multiple fields.



Posted By: Ingo
Date Posted: 30 Apr 19 at 11:10AM
some background hints regarding appearance streams directly from the publishers:
https://www.debenu.com/kb/appearance-streams-pdf-form-fields/



-------------
Cheers,
Ingo




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk