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

Notification

Icon
Error

Options
Go to last post Go to first unread
stan  
#1 Posted : Tuesday, December 10, 2019 1:00:55 PM(UTC)
stan

Rank: Member

Groups: Registered
Joined: 2/21/2019(UTC)
Posts: 13

Is it possible to delete an individual field from a pdf?
Paul Rayman  
#2 Posted : Monday, December 16, 2019 12:17:08 AM(UTC)
Paul Rayman

Rank: Administration

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

Thanks: 3 times
Was thanked: 110 time(s) in 107 post(s)
Hi,

I guess so.
You should delete the widget annotation of that field. And the field itself in the Interactive Form Dictionary.

For example
Code:

using(var doc = PdfDocument.Load(@"e:\ABWORK\_Projects\PDFAnnotator\Shared.Tests\Files\test002.pdf", new PdfForms()))
{
    var field = doc.FormFill.InterForm.Fields.Single(item => item.FullName == "Column6_Szn77rtV*0hjPOwPY0vuDA");
    var dict = doc.FormFill.InterForm.Dictionary;
    var fieldsArray = dict["Fields"].As<PdfTypeArray>();
    var refToField = fieldsArray.Single(item => item.As<PdfTypeDictionary>().Handle == field.Dictionary.Handle);

    foreach (var page in doc.Pages)
    {
        if (page.Annots == null)
            continue;
        foreach (var ctrl in field.Controls)
        {
            var annot = page.Annots.GetByDictionary(ctrl.Dictionary);
            if (annot != null)
                page.Annots.Remove(annot);
        }
    }
    fieldsArray.Remove(refToField);
              
    doc.Save(@"e:\36\test.pdf", SaveFlags.NoIncremental | SaveFlags.RemoveUnusedObjects);
}
stan  
#3 Posted : Tuesday, December 17, 2019 6:43:05 AM(UTC)
stan

Rank: Member

Groups: Registered
Joined: 2/21/2019(UTC)
Posts: 13

Thank you very much!
Users browsing this topic
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.