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
DFletcher  
#1 Posted : Wednesday, March 29, 2017 12:12:05 PM(UTC)
Quote
DFletcher

Rank: Member

Groups: Registered
Joined: 12/27/2016(UTC)
Posts: 10
United States

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

DFletcher  
#2 Posted : Wednesday, March 29, 2017 1:09:44 PM(UTC)
Quote
DFletcher

Rank: Member

Groups: Registered
Joined: 12/27/2016(UTC)
Posts: 10
United States

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

DFletcher  
#3 Posted : Wednesday, March 29, 2017 7:23:59 PM(UTC)
Quote
DFletcher

Rank: Member

Groups: Registered
Joined: 12/27/2016(UTC)
Posts: 10
United States

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

Paul Rayman  
#4 Posted : Monday, April 3, 2017 9:09:27 AM(UTC)
Quote
Paul Rayman

Rank: Administration

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

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
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.

Edited by user Monday, April 3, 2017 9:11:20 AM(UTC)  | Reason: Not specified

Quick Reply Show Quick Reply
Users browsing this topic
Guest (3)
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.