我正在编写PDF,主要思想是提取pdf内容,包括图像、文本以及复选框,至于文本和图像,我提取文本内容和图像,但我无法提取复选框数据。我已经尝试过itextsharp和另一个开源工具,无法获得检查状态(比如true或false )。
发布于 2022-09-14 11:36:20
我的c#很生疏,但是使用iText的最新版本,应该是这样的:
PdfDocument doc = new PdfDocument(new PdfReader(@"c:\\temp\\form.pdf"));
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, false);
IDictionary<string, PdfFormField> fields = form.GetFormFields();
foreach (KeyValuePair<string, PdfFormField> entry in fields)
{
PdfFormField field = entry.Value;
if (field is PdfButtonFormField)
{
Console.WriteLine(entry.Key + " has " + field.GetValueAsString());
}
}
其中,GetValueAsString()通常有“是”表示选中或“关闭”,或空表示未选中。
https://stackoverflow.com/questions/73712861
复制相似问题