handle checked state of radio buttons and checkboxes

This commit is contained in:
Eliot Jones
2019-11-27 15:34:28 +00:00
parent 910e22a4e9
commit ed53773c7b
4 changed files with 108 additions and 25 deletions

View File

@@ -2,6 +2,7 @@
{
using System;
using System.Linq;
using AcroForms.Fields;
using Xunit;
public class AcroFormsBasicFieldsTests
@@ -53,5 +54,38 @@
Assert.Equal(18, fields.Count);
}
}
[Fact]
public void GetsRadioButtonState()
{
using (var document = PdfDocument.Open(GetFilename(), ParsingOptions.LenientParsingOff))
{
var form = document.GetForm();
var radioButtons = form.Fields.OfType<AcroRadioButtonsField>().ToList();
Assert.Equal(2, radioButtons.Count);
// ReSharper disable once PossibleInvalidOperationException
var ordered = radioButtons.OrderBy(x => x.Children.Min(y => y.Bounds.Value.Left)).ToList();
var left = ordered[0];
Assert.Equal(2, left.Children.Count);
foreach (var acroFieldBase in left.Children)
{
var button = Assert.IsType<AcroRadioButtonField>(acroFieldBase);
Assert.False(button.IsSelected);
}
var right = ordered[1];
Assert.Equal(2, right.Children.Count);
var buttonOn = Assert.IsType<AcroRadioButtonField>(right.Children[0]);
Assert.True(buttonOn.IsSelected);
var buttonOff = Assert.IsType<AcroRadioButtonField>(right.Children[1]);
Assert.False(buttonOff.IsSelected);
}
}
}
}