iTextSharp发送PdfFormFieldvalues到服务器
本文关键字:服务器 PdfFormFieldvalues 发送 iTextSharp | 更新日期: 2023-09-27 18:08:18
由于某些原因,我无法将PdfFormField值发送到服务器。当我点击提交按钮时,它只发送数据从与Acrobat创建的字段到服务器,而不是与iTextSharp编程创建的字段。我正在使用c#。
这是我创建文本字段的方法:
Rectangle rec = new Rectangle(x, y-h, x+w, y);
cb.SaveState();
PdfGState state = new PdfGState();
cb.SetGState(state);
state.FillOpacity = opac;
state.StrokeOpacity = bopac;
cb.Rectangle(x, y - h, w, h);
cb.FillStroke();
cb.RestoreState();
这是我的提交按钮:
PdfContentByte cb = writer.DirectContent;
Rectangle _rect;
PdfFormField _Field1;
_rect = new Rectangle(25, 15, 120, 40);
PushbuttonField button = new PushbuttonField(writer, _rect, "Button0");
button.BackgroundColor = new GrayColor(0.75f);
button.BorderColor = GrayColor.GRAYBLACK;
button.BorderWidth = 1;
button.BorderStyle = PdfBorderDictionary.STYLE_BEVELED;
button.TextColor = GrayColor.GRAYBLACK;
button.FontSize = 12;
button.Text = "Confirm Order";
button.Layout = PushbuttonField.LAYOUT_ICON_LEFT_LABEL_RIGHT;
button.ScaleIcon = PushbuttonField.SCALE_ICON_ALWAYS;
button.ProportionalIcon = true;
button.IconHorizontalAdjustment = 0;
_Field1 = button.Field;
int flags = PdfAction.SUBMIT_XFDF | PdfAction.SUBMIT_INCLUDE_NO_VALUE_FIELDS;
_Field1.Action = PdfAction.CreateSubmitForm(@"http://127.0.0.1/index.php", null, flags);
writer.AddAnnotation(_Field1);
您在上面的代码中没有创建表单字段,您只是创建了一个矩形。检查TextField
writer.AddAnnotation(new iTextSharp.text.pdf.TextField(writer, rect, "FirstName").GetTextField());