mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-24 13:23:40 +08:00
#24 add options to list box
This commit is contained in:
@@ -220,33 +220,35 @@
|
||||
throw new PdfDocumentFormatException($"An option array containing array elements should contain 2 strings, instead got: {optionArrayToken}.");
|
||||
}
|
||||
|
||||
string exportValue;
|
||||
if (DirectObjectFinder.TryGet(optionArrayToken.Data[0], tokenScanner, out StringToken exportValueStringToken))
|
||||
{
|
||||
|
||||
exportValue = exportValueStringToken.Data;
|
||||
}
|
||||
else if (DirectObjectFinder.TryGet(optionArrayToken.Data[0], tokenScanner, out HexToken exportValueHexToken))
|
||||
{
|
||||
|
||||
exportValue = exportValueHexToken.Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PdfDocumentFormatException($"An option array array element's first value should be the export value string, instead got: {optionArrayToken.Data[0]}.");
|
||||
}
|
||||
|
||||
string name;
|
||||
if (DirectObjectFinder.TryGet(optionArrayToken.Data[1], tokenScanner, out StringToken nameStringToken))
|
||||
{
|
||||
|
||||
name = nameStringToken.Data;
|
||||
}
|
||||
else if (DirectObjectFinder.TryGet(optionArrayToken.Data[1], tokenScanner, out HexToken nameHexToken))
|
||||
{
|
||||
|
||||
name = nameHexToken.Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new PdfDocumentFormatException($"An option array array element's second value should be the option name string, instead got: {optionArrayToken.Data[1]}.");
|
||||
}
|
||||
|
||||
|
||||
options.Add(new AcroChoiceOption(i, name, exportValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -264,7 +266,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
var field = new AcroListBoxField(fieldDictionary, fieldType, choiceFlags, information);
|
||||
var field = new AcroListBoxField(fieldDictionary, fieldType, choiceFlags, information, options);
|
||||
result = field;
|
||||
}
|
||||
}
|
||||
|
@@ -114,11 +114,14 @@
|
||||
{
|
||||
public AcroChoiceFieldFlags Flags { get; }
|
||||
|
||||
public AcroListBoxField(DictionaryToken dictionary, string fieldType, AcroChoiceFieldFlags fieldFlags,
|
||||
AcroFieldCommonInformation information) :
|
||||
public IReadOnlyList<AcroChoiceOption> Options { get; }
|
||||
|
||||
public AcroListBoxField(DictionaryToken dictionary, string fieldType, AcroChoiceFieldFlags fieldFlags,
|
||||
AcroFieldCommonInformation information, IReadOnlyList<AcroChoiceOption> options) :
|
||||
base(dictionary, fieldType, (uint)fieldFlags, information)
|
||||
{
|
||||
Flags = fieldFlags;
|
||||
Options = options ?? throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user