使用itex sharp 1.4.6.0版在PDFfile中添加单选按钮
我写这段代码是为了创建单选按钮使用itex sharp 1.4.6.0版在PDFfile中添加单选按钮,pdf,c#-4.0,radio-button,itextsharp,Pdf,C# 4.0,Radio Button,Itextsharp,我写这段代码是为了创建单选按钮 SizeF size = new SizeF(FieldBound.Width / 2, FieldBound.Height / 2); PdfContentByte contentByte = PDFStamper.GetOverContent(item.PageNumber); PdfAppearance[] radioButtonStates =
SizeF size = new SizeF(FieldBound.Width / 2, FieldBound.Height / 2);
PdfContentByte contentByte = PDFStamper.GetOverContent(item.PageNumber);
PdfAppearance[] radioButtonStates = new PdfAppearance[2];
radioButtonStates[0] = contentByte.CreateAppearance(FieldBound.Width, FieldBound.Height);
radioButtonStates[0].Circle(size.Width, size.Height, size.Width <= size.Height ? size.Width - 1 : size.Height - 1);
radioButtonStates[0].Stroke();
radioButtonStates[1] = contentByte.CreateAppearance(FieldBound.Width, FieldBound.Height);
radioButtonStates[1].Circle(size.Width, size.Height, size.Width <= size.Height ? size.Width - 1 : size.Height - 1);
radioButtonStates[1].Stroke();
radioButtonStates[1].Circle(size.Width, size.Height, size.Width <= size.Height ? (size.Width / 2) - 1 : (size.Height / 2) - 1);
radioButtonStates[1].FillStroke();
PdfFormField radioButton = PdfFormField.CreateRadioButton(PDFStamper.Writer, false);
radioButton.FieldName = (string.IsNullOrEmpty(item.GroupName) ? item.Name : item.GroupName);
radioButton.UserName = item.ToolTip;
radioButton.Rect = FieldBound;
radioButton.DefaultValueAsString = (item.Value.ToLower() == "true" ? "Yes" : "No");
if (item.ReadOnly)
radioButton.SetFieldFlags(BaseField.READ_ONLY);
if (item.Required)
radioButton.SetFieldFlags(BaseField.REQUIRED);
radioButton.Flags = PdfFormField.FLAGS_PRINT;
radioButton = SetRadioButtonAppearance(PDFStamper.Writer, FieldBound, radioButton, radioButtonStates, true);
PDFStamper.AddAnnotation(radioButton, item.PageNumber);
“是”单选按钮是在我打开pdf文件时创建的,它显示此错误
编辑PDF将导致PDF不再符合PDF/a,是否确实要继续
注意:如果编辑完成后需要PDF/A格式,请确保使用“保存文件->另存为其他->PDF/A”
有人能帮我解决我所缺少的问题吗您使用的iTextSharp版本的日期是2006年10月。除了该版本存在的技术和法律问题外,您还应该使用使用将近9年的软件。请升级。只是为了进一步补充Bruno的评论,PDF/A规范发布时才刚刚一年,所以据我所知,您的版本甚至都不知道。根据PDF/A-1在2.0.5版中添加。
private PdfFormField SetRadioButtonAppearance(PdfWriter Writer, iTextSharp.text.Rectangle Rectangle, PdfFormField RadioButtonField, PdfAppearance[] OnOff, bool On)
{
PdfFormField Field = PdfFormField.CreateRadioButton(Writer,true);
Field.Flags = PdfFormField.FLAGS_PRINT;
Field.SetWidget(Rectangle, PdfAnnotation.HIGHLIGHT_INVERT);
if (On)
Field.AppearanceState = "0";
else
Field.AppearanceState = "Off";
Field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "0", OnOff[1]);
Field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", OnOff[0]);
Field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", OnOff[0]);
Field.SetAppearance(PdfAnnotation.APPEARANCE_DOWN, "0", OnOff[1]);
Field.SetAppearance(PdfAnnotation.APPEARANCE_DOWN, "Off", OnOff[0]);
Field.SetAppearance(PdfAnnotation.APPEARANCE_DOWN, "On", OnOff[0]);
RadioButtonField.AddKid(Field);
return RadioButtonField;
}