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 > General Discussion
  New Posts New Posts RSS Feed - SetFormFieldValue doesnt work when field type is P
  FAQ FAQ  Forum Search   Register Register  Login Login

SetFormFieldValue doesnt work when field type is P

 Post Reply Post Reply
Author
Message
fletchsod View Drop Down
Team Player
Team Player


Joined: 11 Sep 20
Status: Offline
Points: 40
Post Options Post Options   Thanks (0) Thanks(0)   Quote fletchsod Quote  Post ReplyReply Direct Link To This Post Topic: SetFormFieldValue doesnt work when field type is P
    Posted: 14 Sep 20 at 4:53PM
I noticed I can set the field's value if it is a textbox but I can't if it is a Parent.  So, how do you make this work w/ Parent?

var fieldTypeId = pdfApp.GetFormFieldType(1);
if (fieldTypeId == 1)
   // Textbox
   pdfApp.SetFormFieldValue(1, "Foo");
else if (fieldTypeId == 7)
{
   // Parent
   pdfApp.SetFormFieldValue(2, "Foo");
}


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: 14 Sep 20 at 7:44PM
Hi Scott,

don't know much about parent-handling but if there's no other with an idea:
How to extract (parent)content from a pdf-form:
https://www.debenu.com/kb/programmatically-extract-form-field-data-pdf-files/

Another short sample:
http://www.quickpdf.org/forum/checkbox-values_topic2559.html

Perhaps this link to an old thread can help as well?
http://www.quickpdf.org/forum/forum_posts.asp?TID=3702&KW=Form+field+Parent&PID=14763&title=how-to-use-parent-child-fields#14763


Cheers and welcome here,
Ingo
Cheers,
Ingo

Back to Top
fletchsod View Drop Down
Team Player
Team Player


Joined: 11 Sep 20
Status: Offline
Points: 40
Post Options Post Options   Thanks (0) Thanks(0)   Quote fletchsod Quote  Post ReplyReply Direct Link To This Post Posted: 14 Sep 20 at 8:13PM
I found out that looping through FormFieldCount(), using GetFormFieldType(), GetFormFieldTitle() & SetFormFieldValue doesn't work w/ this PDF file I'm using.  Turned out I have to use Annotation stuff to get this working.  So far, I found AnnotationCount() & GetAnnotStrProperty().  Is there better info on trying to get Field Name, finding out whether it is TextField, CheckBoxField or RadioButtonField, & assigning value to it?  This is still a work in progress for me.  Thanks.

Edited by fletchsod - 14 Sep 20 at 10:46PM
Back to Top
fletchsod View Drop Down
Team Player
Team Player


Joined: 11 Sep 20
Status: Offline
Points: 40
Post Options Post Options   Thanks (0) Thanks(0)   Quote fletchsod Quote  Post ReplyReply Direct Link To This Post Posted: 14 Sep 20 at 8:51PM
This is what we used in GrapeCity code that I'm migrating from.

            pdfDocument.Load(pdfFileStream);

            var pdfFieldNames = pdfDocument.AcroForm.Fields.Select(v => v.Name).ToList();
            var checkboxList = new Dictionary<string, int>();
            var radioList = new Dictionary<string, int>();

            // Previously, document.AcroForm.Fields was being used to retrieve PDF fields. However, this caused issues 
            // with multiple fields having the same name (e.g. "P Req Signature"), in that all but one of those fields 
            // would be ignored. Looking, instead, at each page's annotations seems to be the solution.
            foreach (var page in pdfDocument.AcroForm.Doc.Pages)
            {
                foreach (var annotation in page.Annotations)
                {
                    if (annotation.GetType() == typeof(WidgetAnnotation))
                    {
                        var widgetAnnotation = annotation as WidgetAnnotation;
                        var fieldName = widgetAnnotation.Field.Name;
                        TextField txtField;
                        CheckBoxField chkField;
                        RadioButtonField rdbField;
                        bool isString = true;  // Do we really need this?

                        widgetAnnotation.Border.Style = BorderStyle.None;

                        if (pdfFieldNames.Contains(fieldName))
                        { 
                            var fieldResult = _formService.SendDpValuesToPdf(fieldName, formWriter, ref isString);
                            if (fieldResult.Value != null)
                            {
                                if ((txtField = widgetAnnotation.Field as TextField) != null)
                                {
                                    //if (fieldValue.StartsWith(_signaturePrefix) && fieldValue.EndsWith(_signatureSuffix))
                                    if (fieldResult.Value.StartsWith(@"\"))
                                    {
                                        // This is for DocuSign.
                                        // The text layout used to render input fields when flattening the document:
                                        var _inputTl = new gcText::TextLayout();
                                        _inputTl.ParagraphAlignment = gcText::ParagraphAlignment.Center;
                                        // The text format used for input fields:
                                        var _inputTf = new gcText::TextFormat();
                                        _inputTf.Font = StandardFonts.Courier;  // Isn't it suppose to be Helvetica instead of "Courier New"?
                                        _inputTf.ForeColor = dotnetDrawing::Color.Transparent;
                                        _inputTf.FontSize = 4;
                                        _inputTf.FontBold = false;

                                        _inputTl.Clear();
                                        _inputTl.Append(fieldResult.Value, _inputTf);
                                        _inputTl.MaxHeight = widgetAnnotation.Rect.Height;
                                        _inputTl.PerformLayout(true);
                                        widgetAnnotation.Page.Graphics.DrawTextLayout(_inputTl, widgetAnnotation.Rect.Location);
                                    }
                                    else
                                    {
                                        //widgetAnnotation.Field.Value = fieldValue;
                                        txtField.Value = fieldResult.Value;
                                        txtField.RichText = false;
                                    }
                                }
                                else if ((chkField = widgetAnnotation.Field as CheckBoxField) != null)
                                {
                                    // TODO - Change checkbox style from "check" mark to "cross" mark.
                                    //      - https://www.grapecity.com/documents-api-pdf/docs/readme/version3.1.0.508.html
                                    //        (Only version 3.1.0.508 & up support this).
                                    //        (Added WidgetAnnotation.CheckStyle property. It specifies the style of check mark used if the WidgetAnnotation is linked to CheckBoxField or RadioButtonField).
                                    //      - https://www.grapecity.com/documents-api-pdf/docs/online/GrapeCity.Documents.Pdf~GrapeCity.Documents.Pdf.Annotations.CheckStyle.html
                                    //      - 
                                    //chkField.???? = CheckStyle.Cross;

                                    chkField.Value = EvaluatePdfCheckboxField(chkField, checkboxList, fieldResult.Value);
                                }
                                else if ((rdbField = widgetAnnotation.Field as RadioButtonField) != null)
                                {
                                    rdbField.Value = EvaluatePdfRadiobuttonField(rdbField, radioList, fieldResult.Value);
                                }
                            }
                        }
                    }
                }
            }
            //var foo1 = ((CheckBoxField)((WidgetAnnotation)pdfDocument.AcroForm.Doc.Pages[0].Annotations[12]).Field).Value;
            //var foo2 = ((CheckBoxField)((WidgetAnnotation)pdfDocument.AcroForm.Doc.Pages[0].Annotations[13]).Field).Value;
            //var foo3 = ((CheckBoxField)((WidgetAnnotation)pdfDocument.AcroForm.Doc.Pages[0].Annotations[14]).Field).Value;

            SetPdfFieldReadOnly(pdfDocument.AcroForm.Fields);



Edited by fletchsod - 15 Sep 20 at 3:11PM
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: 15 Sep 20 at 7:36AM
What type is the pdf... acro or xfa?
xfa is more complicated with QuickPDF...
BTW: Think you can read but you can't SET the parent field-content.
The parent field is more like a group for single field values.
Try searching in the reference or here in the samples section with:
GetFormFieldKidCount
GetFormFieldKidTempIndex


Cheers,
Ingo

Back to Top
fletchsod View Drop Down
Team Player
Team Player


Joined: 11 Sep 20
Status: Offline
Points: 40
Post Options Post Options   Thanks (0) Thanks(0)   Quote fletchsod Quote  Post ReplyReply Direct Link To This Post Posted: 15 Sep 20 at 2:22PM
Acro, or AcroForm.

I did as what you suggested & it doesn't seem to work.  At least we're in the right direction.  Seem it doesn't work w/ duplicate field names.

I was looking at this at http://www.quickpdf.org/forum/how-to-use-parent-child-fields_topic3702.html & it doesn't do the trick for me.

Suggestions or better examples that works?


        private void UpdateFieldValue(PDFLibrary pdfApp, string fieldName, string value)
        {
            for (int fieldIX = 0; fieldIX < pdfApp.FormFieldCount(); fieldIX++)
            { 
                if (pdfApp.GetFormFieldTitle(fieldIX) == fieldName)
                {
                    pdfApp.SetFormFieldValue(fieldIX, value);
                    pdfApp.SetFormFieldDefaultValue(fieldIX, value);
                    var childCount = pdfApp.GetFormFieldKidCount(fieldIX);
                    if (childCount > 0)
                    { 
                        for (int childIX = 0; childIX < childCount; childIX++)
                        {
                            var tempIX = pdfApp.GetFormFieldKidTempIndex(fieldIX, childIX);
                            pdfApp.SetFormFieldValue(tempIX, value);
                            pdfApp.SetFormFieldDefaultValue(tempIX, value);
                            pdfApp.UpdateAppearanceStream(tempIX);
                        }
                    }
                }
            }
        }



Edited by fletchsod - 15 Sep 20 at 3:11PM
Back to Top
fletchsod View Drop Down
Team Player
Team Player


Joined: 11 Sep 20
Status: Offline
Points: 40
Post Options Post Options   Thanks (0) Thanks(0)   Quote fletchsod Quote  Post ReplyReply Direct Link To This Post Posted: 15 Sep 20 at 3:47PM
Ah!  This script does work.  I was just assigning blank value to some fields due to field name matching issue.  When I replaced blank value with "zzz", that "zzz" showed up. so, there's some issue with "fieldName" when retrieving it from the database.  At least I know what the issue is now, I thought it was PDF programming issues cuz this product is all new to us.  Thanks for your help!

Edited: Turned out the field name was showing a dot at the end, example "Buyer_Fullname." which is a child fieldname & that mess up everything because it is not a correct field Title name.

                    var fieldName = pdfApp.GetFormFieldTitle(fieldIX);
                    if (!string.IsNullOrEmpty(fieldName))
                    {
                        bool isString = true;  // Do we really need this?  (It is unused here).
                        var fieldResult = _formService.SendDpValuesToPdf(fieldName, formWriter, ref isString);
                        if (fieldResult.Value != null)
                        {
                            var fieldValue = string.IsNullOrEmpty(fieldResult.Value) ? "zzz" : fieldResult.Value;
if (fieldValue == "zzz")
{
    var debugBreakpoint = "dd";
}
                            pdfApp.SetFormFieldValue(fieldIX, fieldValue);
                            pdfApp.UpdateAppearanceStream(fieldIX);
                            pdfApp.SetFormFieldDefaultValue(fieldIX, fieldValue);
                            for (int childIX = 0; childIX < pdfApp.GetFormFieldKidCount(fieldIX); childIX++)
                            {
                                var tempIX = pdfApp.GetFormFieldKidTempIndex(fieldIX, childIX);
                                pdfApp.SetFormFieldValue(tempIX, fieldValue);
                                pdfApp.UpdateAppearanceStream(tempIX);
                                pdfApp.SetFormFieldDefaultValue(tempIX, fieldValue);
                            }
                        }
                    }

                    pdfApp.FlattenFormField(fieldIX);

                    // https://www.debenu.com/docs/pdf_library_reference/SetFormFieldReadOnly.php
                    pdfApp.SetFormFieldReadOnly(fieldIX, 1);
                }
            }



Edited by fletchsod - 15 Sep 20 at 3:56PM
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