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

Notification

Icon
Error

Post a reply
From:
Message:

Maximum number of characters in each post is: 32767
Bold Italic Underline   Highlight Quote Choose Language for Syntax Highlighting Insert Image Insert an existing Attachment or upload a new File... Create Link   Unordered List Ordered List   Left Justify Center Justify Right Justify   Outdent Indent   More BBCode Tags
Font Color Font Size
Security Image:
Enter The Letters From The Security Image:
  Preview Post Cancel

Last 10 Posts (In reverse order)
Paul Rayman Posted: Monday, April 3, 2017 9:09:27 AM(UTC)
 
You are right, you can add a pair Ff - value into dictionary.
Also you can use the FlattenPage method
https://pdfium.patagames...a5-a359-d3dcccb0b422.htm

But this method will take effect after saving the document only.
DFletcher Posted: Wednesday, March 29, 2017 7:23:59 PM(UTC)
 
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));
            }
        }
    }
DFletcher Posted: Wednesday, March 29, 2017 1:09:44 PM(UTC)
 
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
            }
        }
    //}
}
DFletcher Posted: Wednesday, March 29, 2017 12:12:05 PM(UTC)
 
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