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

Notification

Icon
Error

Options
Go to last post Go to first unread
brettr  
#1 Posted : 9 years ago
brettr

Rank: Member

Groups: Registered
Joined: 8/11/2016(UTC)
Posts: 14
United States

Thanks: 1 times
I'm looping through a PDF like this:

foreach (var field in interactiveForm.Fields)
{
//...
}

I'm able to identify a combo box using Patagames.Pdf.Enums.FormFieldTypes.FPDF_FORMFIELD_COMBOBOX.

I need to add values to the combo box but don't see any way to do it. Can you please provide sample code?

Thanks.
Paul Rayman  
#2 Posted : 9 years ago
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,116

Thanks: 8 times
Was thanked: 130 time(s) in 127 post(s)
Code:

PdfCommon.Initialize();
PdfForms forms = new PdfForms();
var doc = PdfDocument.Load(@"d:\0\test002.pdf", forms);

foreach (var field in forms.InterForm.Fields)
{
    if(field.FieldType == FormFieldTypes.FPDF_FORMFIELD_COMBOBOX)
    {
        var dict = field.Dictionary;
        var options = dict["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));
    }
}
doc.Save(@"d:\0\111.pdf", SaveFlags.NoIncremental);


Please note all Dictionaries are available in trial mode or with a multi developer license only.
They are not available with a single developer license or with a small business license.
brettr  
#3 Posted : 9 years ago
brettr

Rank: Member

Groups: Registered
Joined: 8/11/2016(UTC)
Posts: 14
United States

Thanks: 1 times
I don't have field.Dictionary. I'm using 4.0.30319. Do I need to do something to gain access to this?

Note I'm using:

var doc = Patagames.Pdf.Net.PdfDocument.Load(path, new PdfForms();
var interactiveForms = doc.FormFill.InterForm;
foreach (var field in interactiveForms.Fields) {
//...
}

Edited by user 9 years ago  | Reason: Not specified

Paul Rayman  
#4 Posted : 9 years ago
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,116

Thanks: 8 times
Was thanked: 130 time(s) in 127 post(s)
Please upgrade the Pdfium.Net SDK to the latest version:
http://forum.patagames.c...released-on-Nov-06--2016
brettr  
#5 Posted : 9 years ago
brettr

Rank: Member

Groups: Registered
Joined: 8/11/2016(UTC)
Posts: 14
United States

Thanks: 1 times
This update worked. Thanks.

I do set a default via:

field.Value = "test";

and then proceed with adding other items. There is a blank entry in the combo box between the default and the other items I've added. It looks like this:

test1

item1
item2
item3

Is there a way to remove this blank entry?

Also, how do I embed a hidden value with each item?

Thanks.

Edited by user 9 years ago  | Reason: Not specified

Paul Rayman  
#6 Posted : 9 years ago
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,116

Thanks: 8 times
Was thanked: 130 time(s) in 127 post(s)
Originally Posted by: brettr Go to Quoted Post

Is there a way to remove this blank entry?


PdfArra.RemoveAt(...)

Originally Posted by: brettr Go to Quoted Post

Also, how do I embed a hidden value with each item?


The Opt array specifies the list of options in the choice field, each of which is represented by a text string to be displayed on the screen.
Each element of the Opt array contains either this text string by itself or a two-element array, whose second element is the text string and whose first element is a text string representing the export value to be used when exporting interactive form field data from the
document.

so the code like following

Code:

foreach (var field in forms.InterForm.Fields)
{
	if (field.FieldType == FormFieldTypes.FPDF_FORMFIELD_COMBOBOX)
	{
		var dict = field.Dictionary;
		var options = dict["Opt"] as PdfTypeArray;

		var arr = PdfTypeArray.Create();
		arr.AddString("USD_VAL");
		arr.AddString("USD");
		options.Add(arr);

		arr = PdfTypeArray.Create();
		arr.AddString("Pounds_VAL");
		arr.AddString("Pounds");
		options.Add(arr);

		arr = PdfTypeArray.Create();
		arr.AddString("Yen_VAL");
		arr.AddString("Yen");
		options.Add(arr);

		arr = PdfTypeArray.Create();
		arr.AddString("Euro_VAL");
		arr.AddString("Euro");
		options.Add(arr);
	}
}
brettr  
#7 Posted : 9 years ago
brettr

Rank: Member

Groups: Registered
Joined: 8/11/2016(UTC)
Posts: 14
United States

Thanks: 1 times
Thanks!

One other question on this code:

var dict = field.Dictionary;
var options = dict["Opt"] as PdfTypeArray;

I get different keys coming back from field.Dictionary.

You can see there isn't an "Opt" in the list below. Other combos do have "Opt". What is the difference?

The problem is that when I test for dict["Opt"], it can throw an exception if "Opt" isn't there.

AP
DA
F
FT
MK
P
Rect
Subtype
T
Type
V

Thanks again.
Paul Rayman  
#8 Posted : 9 years ago
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,116

Thanks: 8 times
Was thanked: 130 time(s) in 127 post(s)
Originally Posted by: brettr Go to Quoted Post

You can see there isn't an "Opt" in the list below.

Is this combo has some items?

if no then the following code may help

Code:

var dict = field.Dictionary;

var options = PdfTypeArray.Create();
options.Add(PdfTypeString.Create("USD", true));
options.Add(PdfTypeString.Create("Pounds", true));
options.Add(PdfTypeString.Create("Yen", true));
options.Add(PdfTypeString.Create("Euro", true));
dict.Add("Opt", options);

Edited by user 9 years ago  | Reason: Not specified

brettr  
#9 Posted : 9 years ago
brettr

Rank: Member

Groups: Registered
Joined: 8/11/2016(UTC)
Posts: 14
United States

Thanks: 1 times
Excellent. That seems to have resolved the issue. By the way, the dropdown that didn't have "Opt" in it also did not have any display values.

Another question: how do I get one of the items to display as the default? I know there is field.Value and that will display but then I lose the key/value pairing.
brettr  
#10 Posted : 9 years ago
brettr

Rank: Member

Groups: Registered
Joined: 8/11/2016(UTC)
Posts: 14
United States

Thanks: 1 times
Hi Paul. Just pinging this thread hoping you can help with the last past for setting a default comb box key/value. Thanks.
Paul Rayman  
#11 Posted : 9 years ago
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,116

Thanks: 8 times
Was thanked: 130 time(s) in 127 post(s)
I do not quite understand your goals. Simply select the desired item, that's all.
https://pdfium.patagames...f6-519a-201f88c36e80.htm
Code:

interactiveForms.Fields[4].SelectItem(0, true);
brettr  
#12 Posted : 9 years ago
brettr

Rank: Member

Groups: Registered
Joined: 8/11/2016(UTC)
Posts: 14
United States

Thanks: 1 times
Thanks Paul. That works when the combo box is the type of:

Code:
var options = dict["Opt"] as PdfTypeArray;


But not the other type that is missing the "Opt" key. For that one, I add all elements then end with:

Code:
dict.Add("Opt", options);


I'm doing

Code:
field.SelectItem(itemIndex, true);


on both. Do you have any idea why the 2nd version doesn't work? Does it need a different technique?
Paul Rayman  
#13 Posted : 9 years ago
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,116

Thanks: 8 times
Was thanked: 130 time(s) in 127 post(s)
Originally Posted by: brettr Go to Quoted Post
But not the other type that is missing the "Opt" key. For that one, I add all elements then end with:

What do you mean?

Please look at this topic
http://forum.patagames.c...dio-within-group#post638

Edited by user 9 years ago  | Reason: Not specified

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.