logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
mukesh  
#1 Posted : Tuesday, November 1, 2016 10:00:09 PM(UTC)
Quote
mukesh

Rank: Member

Groups: Registered
Joined: 7/14/2016(UTC)
Posts: 20
United States

Thanks: 4 times
I have the following code to populate other fields but don't know how to populate multiple values in a field that is of dropdown type.
Code:

            var _fillForms = new PdfForms();
            using (var _doc = Patagames.Pdf.Net.PdfDocument.Load("c:\temp.pdf", _fillForms))
            {
                var interactiveForms = _doc.FormFill.InterForm;
                foreach (var field in interactiveForms.Fields)
                {
                    try
                    {
                        if (field.FieldType == Patagames.Pdf.Enums.FormFieldTypes.FPDF_FORMFIELD_TEXTFIELD)
                        {
                            field.Value = "TextField populated";
                        }
                        else if (field.FieldType == Patagames.Pdf.Enums.FormFieldTypes.FPDF_FORMFIELD_LISTBOX)
                        {
                            string val;
                            // need to populate the listbox with valid Currency types i.e. US Dollars, British Pounds, Euro etc.
                            field.Value = ??


                        }
                    }
                    catch (Exception ex)
                    {
                        //Log ("Problem populating PDF ",ex);
                    }
                }

                _doc.Save("C:\temp.pdf", Patagames.Pdf.Enums.SaveFlags.NoIncremental);
                _doc.Dispose();
            }
        }

Edited by moderator Wednesday, August 9, 2017 7:24:36 PM(UTC)  | Reason: Not specified

Guest  
#2 Posted : Thursday, November 3, 2016 3:32:07 AM(UTC)
Quote
Guest

Rank: Guest

Groups: Guests
Joined: 1/5/2016(UTC)
Posts: 162

Was thanked: 5 time(s) in 5 post(s)
Looks like you need to use the PdfField.Options Property
https://pdfium.patagames...7e-fb1a-4f70f104f826.htm
mukesh  
#3 Posted : Thursday, November 3, 2016 1:37:25 PM(UTC)
Quote
mukesh

Rank: Member

Groups: Registered
Joined: 7/14/2016(UTC)
Posts: 20
United States

Thanks: 4 times
Thanks for your response.

I looked at it. It seems like that PdfField.Options property is read only property.

What I want to do is populate the listbox/dropdown with certain values dynamically. for example to populate a text field we can just do

field.Value = "100";

how do I populate list box that contains the following options for the user to choose...

1. USD
2. Pounds
3. Yen
4. Euro
Guest  
#4 Posted : Thursday, November 3, 2016 4:43:33 PM(UTC)
Quote
Guest

Rank: Guest

Groups: Guests
Joined: 1/5/2016(UTC)
Posts: 162

Was thanked: 5 time(s) in 5 post(s)
Code:

interactiveForms.Fields[4].SelectItem(0, true);
Guest  
#5 Posted : Thursday, November 3, 2016 6:38:57 PM(UTC)
Quote
Guest

Rank: Guest

Groups: Guests
Joined: 1/5/2016(UTC)
Posts: 162

Was thanked: 5 time(s) in 5 post(s)
interactiveForms.Fields[4].SelectedItem(0,true); would select the first element in that listbox control right?


How do you put multiple values in a listbox control so that it ends up giving the user multiple choices in the listbox to choose from?

i.e. if the listbox takes an xml to populate multiple values, I would it to be something like this

interactiveForms.Fields[4].value = "<currency>
<Text="USD" Value=1/>
<Text="Pounds" Value=2/>
<Text="Yen" Value=3/>
<Text="Euro" Value=4/>
</currency>";



or is there a different method to populate the items in a listbox control?

Guest  
#6 Posted : Friday, November 4, 2016 1:11:16 AM(UTC)
Quote
Guest

Rank: Guest

Groups: Guests
Joined: 1/5/2016(UTC)
Posts: 162

Was thanked: 5 time(s) in 5 post(s)
Do you mean the ListBox is empty? And you want to add a new items to it?

As I know the library does not support adding of new items through Interactive Forms class library.
But we found a workaround for similar task.
Please look at code below. The main idea is use the Root dictionary of the document.

Code:

var acroForms = pdfViewer1.Document.Root["AcroForm"] as PdfTypeDictionary;
var fields = acroForms["Fields"] as PdfTypeArray;
var combo = (fields[4] as PdfTypeIndirect).Direct as PdfTypeDictionary;
var options = combo["Opt"] as PdfTypeArray;

options.Add(PdfTypeString.Create("USD", true));
options.Add(PdfTypeString.Create("Pounds", true));
options.Add(PdfTypeString.Create("Yen", true));
options.Add(PdfTypeString.Create("Euro", true));

Edited by user Friday, November 4, 2016 1:12:30 AM(UTC)  | Reason: Not specified

thanks 1 user thanked Guest for this useful post.
mukesh on 11/4/2016(UTC)
Quick Reply Show Quick Reply
Users browsing this topic
Guest
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.