当前位置: 首页 > news >正文

书香气的域名做网站网站如何快速收录

书香气的域名做网站,网站如何快速收录,自己想做个网站需要多少钱,哈尔滨市建设网通常情况下,PDF文件是不可编辑的,但PDF表单提供了一些可编辑区域,允许用户填写和提交信息。PDF表单通常用于收集信息、反馈或进行在线申请,是许多行业中数据收集和交换的重要工具。 PDF表单可以包含各种类型的输入控件&#xff0…

通常情况下,PDF文件是不可编辑的,但PDF表单提供了一些可编辑区域,允许用户填写和提交信息。PDF表单通常用于收集信息、反馈或进行在线申请,是许多行业中数据收集和交换的重要工具。

PDF表单可以包含各种类型的输入控件,如文本框、复选框、下拉菜单、单选按钮等。本文将介绍如何使用C# 和一个免费.NET库来操作PDF表单,包括以下三个示例:

目录

使用C# 创建PDF表单域

使用C# 填写PDF表单域

使用C# 删除PDF表单域


安装免费.NET PDF库 Free Spire.PDF for .NET (可通过 NuGet安装,或下载后手动引用dll

PM> Install-Package FreeSpire.PDF

常见PDF表单域

Free Spire.PDF for .NET 支持创建、操作多种PDF表域,包括文本框、复选框、组合框、列表框和单选按钮等。下表列出了一些常见的域及其在该免费库中对应的类名。

表单域名类名
文本域PdfTextBoxField
复选框PdfCheckBoxField
组合框PdfComboBoxField
列表框PdfListBoxField
单选按钮PdfRadioButtonListField
普通按钮PdfButtonField
签名域PdfSignatureField

使用C# 创建PDF表单域

使用Free Spire.PDF制作表单域,需要先创建以上各表单域类的对象,然后通过 Bounds 属性设置表单域的位置和大小,最后再通过PdfFormFieldCollection.Add() 方法将表单域绘制到PDF页面指定位置处。

以下是如何在PDF中创建上述常见PDF表单域的C#代码:

using Spire.Pdf;
using Spire.Pdf.Actions;
using Spire.Pdf.Fields;
using Spire.Pdf.Graphics;
using System.Drawing;namespace CreateFillableFormsInPdf
{class Program{static void Main(string[] args){//创建PdfDocument对象PdfDocument pdf = new PdfDocument();//添加一页PdfPageBase page = pdf.Pages.Add();//初始化x、y坐标float baseX = 60;float baseY = 20;//创建两个画刷PdfSolidBrush brush1 = new PdfSolidBrush(new PdfRGBColor(Color.Brown));PdfSolidBrush brush2 = new PdfSolidBrush(new PdfRGBColor(Color.Black));//创建字体PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("微软雅黑", 11f, FontStyle.Regular), true);//添加文本框 page.Canvas.DrawString("姓名:", font, brush1, new PointF(10, baseY));RectangleF tbxBounds = new RectangleF(baseX, baseY, 150, 18);PdfTextBoxField textBox = new PdfTextBoxField(page, "姓名");textBox.Bounds = tbxBounds;textBox.Font = font;pdf.Form.Fields.Add(textBox);baseY += 30;//添加两个复选框page.Canvas.DrawString("民族:", font, brush1, new PointF(10, baseY));RectangleF checkboxBound1 = new RectangleF(baseX, baseY, 15, 15);PdfCheckBoxField checkBoxField1 = new PdfCheckBoxField(page, "选项1");checkBoxField1.Bounds = checkboxBound1;checkBoxField1.Checked = false;page.Canvas.DrawString("汉族", font, brush2, new PointF(baseX + 20, baseY));RectangleF checkboxBound2 = new RectangleF(baseX + 70, baseY, 15, 15);PdfCheckBoxField checkBoxField2 = new PdfCheckBoxField(page, "选项2");checkBoxField2.Bounds = checkboxBound2;checkBoxField2.Checked = false;page.Canvas.DrawString("少数民族", font, brush2, new PointF(baseX + 90, baseY));pdf.Form.Fields.Add(checkBoxField1);pdf.Form.Fields.Add(checkBoxField2);baseY += 30;//添加列表框page.Canvas.DrawString("分公司:", font, brush1, new PointF(10, baseY));RectangleF listboxBound = new RectangleF(baseX, baseY, 150, 50);PdfListBoxField listBoxField = new PdfListBoxField(page, "分公司");listBoxField.Items.Add(new PdfListFieldItem("成都", "成都"));listBoxField.Items.Add(new PdfListFieldItem("武汉", "武汉"));listBoxField.Items.Add(new PdfListFieldItem("深圳", "深圳")); ;listBoxField.Bounds = listboxBound;listBoxField.Font = font;pdf.Form.Fields.Add(listBoxField);baseY += 60;//添加两个单选按钮page.Canvas.DrawString("性别:", font, brush1, new PointF(10, baseY));PdfRadioButtonListField radioButtonListField = new PdfRadioButtonListField(page, "性别");PdfRadioButtonListItem radioItem1 = new PdfRadioButtonListItem("选项1");RectangleF radioBound1 = new RectangleF(baseX, baseY, 15, 15);radioItem1.Bounds = radioBound1;page.Canvas.DrawString("男", font, brush2, new PointF(baseX + 20, baseY));PdfRadioButtonListItem radioItem2 = new PdfRadioButtonListItem("选项2");RectangleF radioBound2 = new RectangleF(baseX + 70, baseY, 15, 15);radioItem2.Bounds = radioBound2;page.Canvas.DrawString("女", font, brush2, new PointF(baseX + 90, baseY));radioButtonListField.Items.Add(radioItem1);radioButtonListField.Items.Add(radioItem2);pdf.Form.Fields.Add(radioButtonListField);baseY += 30;//添加组合框page.Canvas.DrawString("部门:", font, brush1, new PointF(10, baseY));RectangleF cmbBounds = new RectangleF(baseX, baseY, 150, 18);PdfComboBoxField comboBoxField = new PdfComboBoxField(page, "部门");comboBoxField.Bounds = cmbBounds;comboBoxField.Items.Add(new PdfListFieldItem("财务", "财务"));comboBoxField.Items.Add(new PdfListFieldItem("技术", "技术"));comboBoxField.Items.Add(new PdfListFieldItem("采购", "采购"));comboBoxField.Items.Add(new PdfListFieldItem("销售", "销售"));comboBoxField.Font = font;pdf.Form.Fields.Add(comboBoxField);baseY += 30;//添加签名域page.Canvas.DrawString("签名:", font, brush1, new PointF(10, baseY));PdfSignatureField sgnField = new PdfSignatureField(page, "签名域");RectangleF sgnBounds = new RectangleF(baseX, baseY, 150, 80);sgnField.Bounds = sgnBounds;pdf.Form.Fields.Add(sgnField);baseY += 90;//添加按钮page.Canvas.DrawString("按钮:", font, brush1, new PointF(10, baseY));RectangleF btnBounds = new RectangleF(baseX, baseY, 50, 18);PdfButtonField buttonField = new PdfButtonField(page, "按钮");buttonField.Bounds = btnBounds;buttonField.Text = "提交";buttonField.Font = font;PdfSubmitAction submitAction = new PdfSubmitAction("https://www.****.com");submitAction.DataFormat = SubmitDataFormat.Html;buttonField.Actions.MouseDown = submitAction;pdf.Form.Fields.Add(buttonField);//保存文件pdf.SaveToFile("PDF表单.pdf", FileFormat.PDF);}}
}

生成文件:

使用C# 填写PDF表单域

填充表单域需要先获取PDF中的所有表单字段,然后确定其表单类型,最后再填写数据或从预定列表中选择值。

以下是如何填充现有PDF表单域的C#代码:

using Spire.Pdf;
using Spire.Pdf.Fields;
using Spire.Pdf.Widget;namespace FillFormFields
{class Program{static void Main(string[] args){//加载PDF表单PdfDocument pdf = new PdfDocument();pdf.LoadFromFile("PDF表单.pdf");//获取文档中的表单PdfFormWidget form = (PdfFormWidget)pdf.Form;//获取表单域集合PdfFormFieldWidgetCollection formWidgetCollection = form.FieldsWidget;//遍历表单域for (int i = 0; i < formWidgetCollection.Count; i++){//获取指定域PdfField field = formWidgetCollection[i];//判断该表单域是否为文本框if (field is PdfTextBoxFieldWidget){if (field.Name == "姓名"){//填充文本PdfTextBoxFieldWidget textBoxField = (PdfTextBoxFieldWidget)field;textBoxField.Text = "张三";}}//判断该表单域是否为单选按钮if (field is PdfRadioButtonListFieldWidget){if (field.Name == "性别"){//为单选按钮选定一个值PdfRadioButtonListFieldWidget radioButtonListField = (PdfRadioButtonListFieldWidget)field;radioButtonListField.SelectedIndex = 0;}}//判断该表单域是否为组合框if (field is PdfComboBoxWidgetFieldWidget){if (field.Name == "部门"){//为组合框选定一个值PdfComboBoxWidgetFieldWidget comboBoxField = (PdfComboBoxWidgetFieldWidget)field;int[] index = { 1 };comboBoxField.SelectedIndex = index;}}//判断该表单域是否为复选框if (field is PdfCheckBoxWidgetFieldWidget){//设置复选框的"已选中"状态PdfCheckBoxWidgetFieldWidget checkBoxField = (PdfCheckBoxWidgetFieldWidget)field;switch (checkBoxField.Name){case "选项1":checkBoxField.Checked = true;break;}}//判断该表单域是否为列表框if (field is PdfListBoxWidgetFieldWidget){if (field.Name == "分公司"){//为列表框选定一个值PdfListBoxWidgetFieldWidget listBox = (PdfListBoxWidgetFieldWidget)field;int[] index = { 1 };listBox.SelectedIndex = index;}}}//保存文件pdf.SaveToFile("填充PDF表单域.pdf", FileFormat.PDF);}}
}

输出结果:

 

使用C# 删除PDF表单域

Free Spire.PDF支持通过索引或名称删除指定的表单域或删除所有表单域。

以下是如何删除PDF表单域的C#代码:

using Spire.Pdf;
using Spire.Pdf.Fields;
using Spire.Pdf.Widget;namespace RemoveFormFields
{class Program{static void Main(string[] args){//加载PDF表单PdfDocument pdf = new PdfDocument();pdf.LoadFromFile("PDF表单.pdf");//获取文档中的表单域PdfFormWidget formWidget = pdf.Form as PdfFormWidget;//遍历表单域for (int i = formWidget.FieldsWidget.List.Count - 1; i >= 0; i--){//获取指定表单域PdfField field = formWidget.FieldsWidget.List[i] as PdfField;//删除表单域formWidget.FieldsWidget.Remove(field);}//通过表单域名获取指定表单//PdfField field = formWidget.FieldsWidget["name"];//删除该表单域//formWidget.FieldsWidget.Remove(field);//保存PDF文件pdf.SaveToFile("删除PDF表单域.pdf");}}
}

以上代码演示了PDF表单的基本操作,包括添加文本框、复选框、组合框、单选按钮等各种常见的表单域,填写现有PDF表单,以及删除PDF表单。Free Spire.PDF免费库该支持其他多种PDF元素,点击查看更多示例。

http://www.dt0577.cn/news/29143.html

相关文章:

  • 如何做家具网站seo网络推广知识
  • 深圳好的高端企业网站建设公司成人职业技能培训学校
  • dede如何做手机网站收录排名好的发帖网站
  • wordpress小说网站模板百度百家号
  • 阿里云建网站2345网址导航中国最好
  • 保定网站开发公司seo短视频网页入口引流
  • 网站的搜索引擎方案创意设计
  • 株洲网站建设网络运营怎么学
  • 建设网站远达seo网站外包公司
  • 中国做二手房最大的网站百度问答官网
  • 知乎有趣的网站培训课程设计
  • 没备案的网站怎么做淘客seo关键词排名工具
  • 哈尔滨做网站价格谷歌在线搜索
  • 公司网站二维码怎么做的网络推广工作内容怎么写
  • 电子商务网站总体规划的内容网页设计与制作作业成品
  • 用wordpress复制一个网站模板宁波谷歌seo推广
  • 宽屏蓝色企业网站源码大型seo公司
  • 怎样做网络推广好商品seo优化是什么意思
  • 做网站需要啥济南网站优化排名
  • 免费电视剧网站大全在线观看互联网营销推广怎么做
  • 浙江网站建设电话外贸网站平台都有哪些
  • ui图标素材网站东莞最新消息今天
  • 期末成绩怎么做网站互联网销售模式
  • 免费模板下载软件seo优化是指
  • 上海企业网站模板建站哪家好排名软件下载
  • 株洲网站优化现在感染症状有哪些
  • 相亲网站如何做掉发脱发严重是什么原因
  • 江门网站建设代运营公司是怎么运营的
  • python做网站显示表格网络营销策略存在的问题
  • 新网站建设验收腾讯云服务器