Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - How to use Parent / Child Fields
  FAQ FAQ  Forum Search   Register Register  Login Login

How to use Parent / Child Fields

 Post Reply Post Reply
Author
Message
waynefulcher View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Jun 08
Location: United States
Status: Offline
Points: 99
Post Options Post Options   Thanks (0) Thanks(0)   Quote waynefulcher Quote  Post ReplyReply Direct Link To This Post Topic: How to use Parent / Child Fields
    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.




Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
waynefulcher View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Jun 08
Location: United States
Status: Offline
Points: 99
Post Options Post Options   Thanks (0) Thanks(0)   Quote waynefulcher Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store