我正在使用从NuGet安装的http://www.pdfsharp.net的PDFSharp版本1.50.4740-beta5。
我能够填写文本表单域和复选框表单域,但根本无法使单选按钮正常工作。我没有错。在将其设置为1之前和之后,SelectedIndex为-1。
[Stack Overflow上的几篇文章帮助我实现了这一目标。是否有人成功使用此产品填充了单选按钮表单字段?这是样本PDF的链接:http://www.myblackmer.com/bluebook/interactiveform_enabled.pdf
((在您建议iTextPdf之前,我已经对它和Aspose.PDF进行了评估,它们不切实际)
//using PdfSharp.Pdf.IO;
//using PdfSharp.Pdf;
//using PdfSharp.Pdf.AcroForms;
string fileName = "x:\\interactiveform_enabled.pdf";
PdfSharp.Pdf.PdfDocument pdfDocument = PdfReader.Open(fileName);
//The populated fields are not visible by default
if (pdfDocument.AcroForm.Elements.ContainsKey("/NeedAppearances"))
{
pdfDocument.AcroForm.Elements["/NeedAppearances"] = new PdfBoolean(true);
}
else
{
pdfDocument.AcroForm.Elements.Add("/NeedAppearances", new PdfBoolean(true));
}
PdfRadioButtonField currentField = (PdfRadioButtonField)(pdfDocument.AcroForm.Fields["Sex"]);
currentField.ReadOnly = false;
currentField.SelectedIndex = 1;
pdfDocument.Flatten();
pdfDocument.Save("x:\\interactiveform_enabled_2.pdf");
我正在使用从NuGet安装的http://www.pdfsharp.net的PDFSharp版本1.50.4740-beta5。我可以填写文本表单域和复选框表单域,但是我无法使单选按钮起作用...
以下内容对我有用: