没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
原创|使用教程|编辑:李显亮|2019-09-05 11:22:18.143|阅读 959 次
概述:Adobe Acrobat Form (AcroForm) 是表单域的集合,用来以交互方式从用户那里收集信息。Spire.PDF支持创建多种交互式表单域,本文将介绍如何创建表单域并设置属性。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
Spire.PDF是一个专业的PDF组件,能够独立地创建、编写、编辑、操作和阅读PDF文件,支持 .NET、Java、WPF和Silverlight。Spire.PDF的PDF API拥有丰富的功能,如安全设置(包括数字签名)、PDF文本/附件/图片提取、PDF文件合并/拆分、元数据更新、章节和段落优化、图形/图像描绘和插入、表格创建和处理、数据导入等等。>>下载Spire.PDF最新试用版
Adobe Acrobat Form (AcroForm) 是表单域的集合,用来以交互方式从用户那里收集信息。Spire.PDF支持创建多种交互式表单域,例如:文本域、单选按钮、复选框、列表框、组合框,并在特定的表单域添加提示文本(Tooltip),方便用户输入正确信息。
创建表单域
//创建PDF文档并添加一页 PdfDocument pdf = new PdfDocument(); PdfPageBase page = pdf.Pages.Add(); //设置font, brush PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial Unicode MS", 10f,FontStyle.Regular), true); PdfBrush brush = PdfBrushes.Black; //定义一些坐标变量并赋初值 float x = 10; float y = 10; float tempX = 0; float tempY = 0; //添加文本框 string text = "文本框: "; page.Canvas.DrawString(text, font, brush, x, y); tempX = font.MeasureString(text).Width + 15; tempY = font.MeasureString(text).Height + 15; PdfTextBoxField textbox = new PdfTextBoxField(page, "TextBox"); textbox.Bounds = new RectangleF(tempX, y, tempX * 2, 15); textbox.BorderWidth = 0.75f; textbox.BorderStyle = PdfBorderStyle.Solid; pdf.Form.Fields.Add(textbox); //添加复选框 text = "复选框: "; y += tempY; page.Canvas.DrawString(text, font, brush, x, y); tempX = font.MeasureString(text).Width + 15; tempY = font.MeasureString(text).Height + 15; PdfCheckBoxField checkbox = new PdfCheckBoxField(page, "CheckBox"); checkbox.Bounds = new RectangleF(tempX, y, 15, 15); checkbox.BorderWidth = 0.75f; checkbox.Style = PdfCheckBoxStyle.Cross; pdf.Form.Fields.Add(checkbox); //添加列表框 text = "列表框: "; y += tempY; page.Canvas.DrawString(text, font, brush, x, y); tempX = font.MeasureString(text).Width + 15; tempY = font.MeasureString(text).Height + 15; PdfListBoxField listbox = new PdfListBoxField(page, "ListBox"); listbox.Bounds = new RectangleF(tempX, y, tempX * 2, tempY * 2); listbox.BorderWidth = 0.75f; for (int i = 0; i < 3; i++) { //添加项目到列表框 string tempText = string.Format("Text {0}", i); string tempValue = string.Format("Value {0}", i); listbox.Items.Add(new PdfListFieldItem(tempText, tempValue)); } pdf.Form.Fields.Add(listbox); //添加单选按钮 text = "单选按钮: "; y += tempY * 2 + 15; page.Canvas.DrawString(text, font, brush, x, y); tempX = font.MeasureString(text).Width + 15; tempY = font.MeasureString(text).Height + 15; PdfRadioButtonListField radiobutton = new PdfRadioButtonListField(page, "RadioButton"); for (int i = 0; i < 3; i++) { PdfRadioButtonListItem item = new PdfRadioButtonListItem(string.Format("rb{0}", i)); item.BorderWidth = 0.75f; item.Bounds = new RectangleF(tempX + i * 20, y, 15, 15); radiobutton.Items.Add(item); } pdf.Form.Fields.Add(radiobutton); //添加组合框 text = "下拉列表框: "; y += tempY; page.Canvas.DrawString(text, font, brush, x, y); tempX = font.MeasureString(text).Width + 15; tempY = font.MeasureString(text).Height + 15; PdfComboBoxField combobox = new PdfComboBoxField(page, "ComboBox"); combobox.Bounds = new RectangleF(tempX, y, tempX, 15); combobox.BorderWidth = 0.75f; for (int i = 0; i < 3; i++) { //添加项目到下拉列表框 string tempText = string.Format("Text {0}", i); string tempValue = string.Format("Value {0}", i); combobox.Items.Add(new PdfListFieldItem(tempText, tempValue)); } pdf.Form.Fields.Add(combobox); //保存文档 pdf.SaveToFile("PDF表单域.pdf");
添加提示文本(Tooltip)
//创建PDF文档并添加一页 PdfDocument pdf = new PdfDocument(); PdfPageBase page = pdf.Pages.Add(); //设置font, brush PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial Unicode MS", 10f, FontStyle.Regular), true); PdfBrush brush = PdfBrushes.Black; //定义一些坐标变量并赋初值 float x = 10; float y = 50; float tempX = 0; float tempY = 0; //添加文本框 string text = "满意指数: "; page.Canvas.DrawString(text, font, brush, x, y); tempX = font.MeasureString(text).Width + 15; tempY = font.MeasureString(text).Height + 15; PdfTextBoxField textbox = new PdfTextBoxField(page, "TextBox"); textbox.Bounds = new RectangleF(tempX, y, tempX * 2, 15); textbox.BorderWidth = 0.75f; textbox.BorderStyle = PdfBorderStyle.Solid; //添加文本提示信息 textbox.ToolTip = "请输入0-5之间的数字"; //添加文本域到fields collection并保存文档 pdf.Form.Fields.Add(textbox); pdf.SaveToFile("添加文本信息.pdf");
当我们把PDF表单域填写完成后,可以将这些域设置为只读来阻止用户修改或删除表单域的内容。Spire.PDF组件支持以下两种方式将PDF表单域设置为只读:
将表单域扁平化
可以使用PdfForm类的IsFlatten属性来将PDF文档中的所有表单域扁平化。代码示例如下:
//加载PDF文档 PdfDocument document = new PdfDocument(); document.LoadFromFile("Form.pdf"); //获取文档中的现有表单域 PdfForm loadedForm = document.Form; //扁平化所有表单域 loadedForm.IsFlatten = true; //保存文档 document.SaveToFile("Flatten1.pdf");
此外,我们还可以通过PdfField类的Flatten属性来扁平化指定表单域:
//加载PDF文档 PdfDocument document = new PdfDocument(); document.LoadFromFile("Form.pdf"); //获取文档中的现有表单域 PdfFormWidget form = document.Form as PdfFormWidget; //扁平化指定表单域 PdfField field = form.FieldsWidget.List[0] as PdfField; field.Flatten = true; //保存文档 document.SaveToFile("Flatten2.pdf");
将表单域设置为只读
将PDF文档中的所有表单域设置为只读,我们可以使用PdfForm类的ReadOnly属性:
//加载PDF文档 PdfDocument document = new PdfDocument(); document.LoadFromFile("Form.pdf"); //获取文档中的现有表单域 PdfForm loadedForm = document.Form; //将所有表单域设置为只读 loadedForm.ReadOnly = true; //保存文档 document.SaveToFile("ReadOnly1.pdf");
将PDF文档中的指定表单域设置为只读,我们可以使用PdfField类的ReadOnly属性:
//加载PDF文档 PdfDocument document = new PdfDocument(); document.LoadFromFile("Form.pdf"); //获取文档中的现有表单域 PdfFormWidget form = document.Form as PdfFormWidget; //将指定表单域设置为只读 PdfField field = form.FieldsWidget.List[0] as PdfField; field.ReadOnly = true; //保存文档 document.SaveToFile("ReadOnly2.pdf");
如果你有任何问题或意见,可在下方评论区留言,点击资源列表查看更多教程资源~
*想要购买正版授权的朋友可以哦~
扫描关注“慧聚IT”微信公众号,及时获取更多产品最新动态及最新资讯
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@wqylolg.cn
无论是零售、物流还是医疗保健,旋转条形码图像的功能都能增强不同应用的灵活性和适应性。使用Aspose.BarCode for Java,您可以轻松旋转条形码图像,确保它们无缝融入应用程序的设计和布局。
借助Aspose.Slides for Java,开发人员可以轻松编辑 PowerPoint 幻灯片(包括表格),以增强演示文稿的效果。
VMProtect 是保护程序代码免遭分析与破解的利器,但很多开发者在实现注册机制时犯了关键性错误,使得再强大的加壳工具也难以阻挡黑客破解。本文将从注册逻辑设计、密钥验证方式、注册状态存储等多个角度,系统拆解常见误区,并结合 VMProtect 的虚拟化和加密策略,提供构建高强度注册保护的实战方案。
在本文中,我们将探讨如何在FastReport .NET中配置与 Apache Ignite 的连接。您将学习通过代码和报表设计器连接插件的必要步骤。
Spire.PDF for .NET是独立的PDF控件,用于.NET程序中创建、编辑和操作PDF文档
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@wqylolg.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢