c# - abcPDF eForm 单选字段 - 值选项包含特殊字符
问题描述
解决方案
I reached out to the WebSupergoo team, and they were extremely helpful. They explained there wasn't a way to select the radio buttons by some sort of index, and that the strings each option refers to has to match the string in the form option.
To that end, there is no way to select the radio button without interacting with the Option object's string, and since the string is malformed, the normal option select code is not working.
As a work-around, in case anyone else finds themselves in my shoes, the WebSupergoo team provided this function:
/// <summary>
/// Checks each field to ensure it has properly formatted options
/// </summary>
/// <param name="field"></param>
/// <returns>An array of options that have been safely formatted</returns>
private static string[] VetField(Field field)
{
List<string> options = new List<string>();
foreach (Field kid in field.Kids)
{
bool different = false;
DictAtom ap1 = kid.Resolve(Atom.GetItem(kid.Atom, "AP")) as DictAtom;
if (ap1 == null) continue;
DictAtom ap2 = new DictAtom();
foreach (var pair1 in ap1)
{
DictAtom apType1 = kid.Resolve(pair1.Value) as DictAtom;
Debug.Assert(apType1 != null); // should never happen
DictAtom apType2 = new DictAtom();
ap2[pair1.Key] = apType2;
foreach (var pair2 in apType1)
{
string name1 = pair2.Key;
StringBuilder sb = new StringBuilder();
foreach (char c in name1)
{
if (c < 128)
sb.Append(c);
}
string name2 = sb.ToString();
if (name1 != name2)
different = true;
apType2[name2] = pair2.Value;
if (pair1.Key == "N")
options.Add(name2);
}
}
if (different)
((DictAtom)kid.Atom)["AP"] = ap2;
}
return options.ToArray();
}
which checks the Option field's strings for formatting issues, and returns a sanitized list of options. So, using the code in the question as an example, I would be able to properly select option radio buttons by doing the following:
Doc theDoc = new Doc();
theDoc.Read(Server.MapPath("fileName.pdf"));
Field areYouHappy = theDoc.Form["Q28_happy"];
string[] options = VetField(areYouHappy); //uses above function to check for formatting errors
areYouHappy.Value = options[0];
theDoc.Save(Server.MapPath("newFileName.pdf"));
This method works great, and I hope it can help someone else in the future!
推荐阅读
- python - 用双引号和换行符在pySpark中读取csv文件
- google-cloud-platform - BigQuery 上传作业返回错误 - 有效负载部分计数错误?
- c - 使用按位和运算符指向数组声明的 C 指针
- azure-sphere - azuresphere 实时应用程序 - 从兼容的预构建 ELF (.out) 文件生成 .image 文件
- sql - 按子查询的 SQL 分组过滤器
- c - C 和内联函数中的独立目标代码
- ruby-on-rails - 如何在 Windows 10 上修复 Rails 缺少的 libcurl 库?
- windows - 客户端USB设备驱动查询
- c# - 当鼠标悬停到统一 EditorGUILayout.Popup() 时,无法添加要显示的工具提示
- javascript - 无法获取 JSON 文件