Rank: Member
Groups: Registered
Joined: 12/27/2016(UTC) Posts: 10 
|
Hi
I am setting the value for interactive form fields, then using Save to create a PDF. The PDF is sent to the user who will view with Acrobat reader etc. I need a way to prevent the user from changing a field value.
Is it possible to set the PdfField Flags property? Or, is it possible to set a Document readonly property? Or, is it possible to flatten a field so that it becomes static text on the PDF?
Thanks! D
|
|
|
|
|
|
Rank: Member
Groups: Registered
Joined: 12/27/2016(UTC) Posts: 10 
|
Hi - I dug into the Dictionary for each field and found that key "Ff" relates to FieldFlags. I can set the read only flag via IntValue() however, I am getting inconsistent results because not all fields have an "Ff" in their dictionary. Is there another way to set the FieldFlags, or should I add "Ff" to the dictionary (if that is even possible)? Code:
foreach (PdfField control in _forms.InterForm.Fields)
{
//if (control.FieldType == FormFieldTypes.FPDF_FORMFIELD_TEXTFIELD)
//{
string k;
PdfTypeBase v;
foreach (var d in control.Dictionary)
{
k = d.Key;
v = d.Value;
[h]if (d.Key == "Ff" && v.ObjectType == IndirectObjectTypes.Number)[/h]
{
PdfTypeNumber n = (PdfTypeNumber)v;
n.IntValue = n.IntValue | (int)FieldFlags.ReadOnly; // ReadOnly == 1
}
}
//}
}
Edited by moderator Monday, April 3, 2017 9:03:48 AM(UTC)
| Reason: Not specified
|
|
|
|
|
|
Rank: Member
Groups: Registered
Joined: 12/27/2016(UTC) Posts: 10 
|
This appears to work. Tweak the control.FieldType condition to include/exclude fields. Code:
foreach (PdfField control in _forms.InterForm.Fields)
{
if (control.FieldType == FormFieldTypes.FPDF_FORMFIELD_TEXTFIELD
|| control.FieldType == FormFieldTypes.FPDF_FORMFIELD_CHECKBOX
|| control.FieldType == FormFieldTypes.FPDF_FORMFIELD_COMBOBOX)
{
string k;
PdfTypeBase v;
bool hasFlags = false;
foreach (var d in control.Dictionary)
{
k = d.Key;
v = d.Value;
if (d.Key == "Ff" && v.ObjectType == IndirectObjectTypes.Number)
{
hasFlags = true;
PdfTypeNumber n = (PdfTypeNumber)v;
n.IntValue = n.IntValue | (int)FieldFlags.ReadOnly;
}
}
if (!hasFlags)
{
PdfTypeNumber fieldFlags = PdfTypeNumber.Create((int)FieldFlags.ReadOnly);
control.Dictionary.Add(new KeyValuePair<string, PdfTypeBase>("Ff", fieldFlags));
}
}
}
Edited by moderator Monday, April 3, 2017 9:04:52 AM(UTC)
| Reason: Not specified
|
|
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,138
Thanks: 10 times Was thanked: 133 time(s) in 130 post(s)
|
|
|
|
|
|
|
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.
Important Information:
The Patagames Software Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close