翻譯|使用教程|編輯:李顯亮|2019-09-12 11:10:42.387|閱讀 707 次
概述:dobe Acrobat Form (AcroForm) 是表單域的集合,用來(lái)以交互方式從用戶(hù)那里收集信息。Spire.PDF支持創(chuàng)建多種交互式表單域,本文將介紹如何讀取和重置表單域字段的值。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
Spire.PDF是一個(gè)專(zhuān)業(yè)的PDF組件,能夠獨(dú)立地創(chuàng)建、編寫(xiě)、編輯、操作和閱讀PDF文件,支持 .NET、Java、WPF和Silverlight。Spire.PDF的PDF API擁有豐富的功能,如安全設(shè)置(包括數(shù)字簽名)、PDF文本/附件/圖片提取、PDF文件合并/拆分、元數(shù)據(jù)更新、章節(jié)和段落優(yōu)化、圖形/圖像描繪和插入、表格創(chuàng)建和處理、數(shù)據(jù)導(dǎo)入等等。>>下載Spire.PDF最新試用版
讀取PDF表單域
//創(chuàng)建PdfDocument實(shí)例并加載示例文檔 PdfDocument pdf = new PdfDocument(); pdf.LoadFromFile("Sample.pdf"); //遍歷FieldsWidget.List獲取所有表單域,并打印出表單域名稱(chēng) PdfFormWidget formWidget = pdf.Form as PdfFormWidget; for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++) { PdfField field = formWidget.FieldsWidget.List[i] as PdfField; string fieldName = field.Name; Console.WriteLine(fieldName); } Console.WriteLine("--------------------------------------"); //遍歷FieldsWidget.List獲取所有表單域,并打印出導(dǎo)出Value為YES的表單域名稱(chēng) Listlist = formWidget.FieldsWidget.GetFieldsByExportValue("Yes"); for (int i = 0; i < list.Count; i++) { string fieldName = list[i].Name; Console.WriteLine(fieldName); } Console.Read();
讀取域里面選擇的值:
//創(chuàng)建PdfDocument實(shí)例并加載示例文檔 PdfDocument pdf = new PdfDocument(); pdf.LoadFromFile("Sample.pdf"); //獲取PDF文檔第一頁(yè) PdfPageBase page = pdf.Pages[0]; //遍歷FieldsWidget.List獲取所有表單域 PdfFormWidget formWidget = pdf.Form as PdfFormWidget; for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++) { PdfField field = formWidget.FieldsWidget.List[i] as PdfField; //獲取單選鈕表單域并輸出所選擇的按鈕值 if (field is PdfRadioButtonListFieldWidget) { PdfRadioButtonListFieldWidget radioButton = field as PdfRadioButtonListFieldWidget; foreach (PdfRadioButtonWidgetItem item in radioButton.WidgetItems) { if (item.Selected) { Console.WriteLine(item.Value); } } } } Console.ReadKey();
//初始化一個(gè)PdfDocument實(shí)例 PdfDocument document = new PdfDocument(); //添加頁(yè)面 PdfPageBase page = document.Pages.Add(); //創(chuàng)建文本框 PdfTextBoxField textBoxField = new PdfTextBoxField(page, "文本框"); //設(shè)置文本框相關(guān)屬性 textBoxField.BorderColor = new PdfRGBColor(Color.AliceBlue); textBoxField.BorderStyle = PdfBorderStyle.Solid; textBoxField.Bounds = new RectangleF(50, 50, 100, 20); textBoxField.Text = "初始字段值"; //添加文本框到文檔 document.Form.Fields.Add(textBoxField); //創(chuàng)建按鈕 PdfButtonField button = new PdfButtonField(page, "重置"); //設(shè)置按鈕相關(guān)屬性 button.Bounds = new RectangleF(80, 100, 50, 20); button.BorderColor = new PdfRGBColor(Color.AliceBlue); button.BorderStyle = PdfBorderStyle.Solid; button.ToolTip = "重置"; button.Font = new PdfFont(PdfFontFamily.Helvetica, 9f); //添加按鈕到文檔 document.Form.Fields.Add(button); //創(chuàng)建PdfResetAction實(shí)例 PdfResetAction resetAction = new PdfResetAction(); //設(shè)置resetAction在點(diǎn)擊按鈕時(shí)執(zhí)行 button.Actions.GotFocus = resetAction; //保存文檔 document.SaveToFile("重置表單字段值.pdf"); document.Close();
*悅滿(mǎn)中秋 · 購(gòu)享好禮,不限量超值優(yōu)惠券免費(fèi)領(lǐng)取,更多活動(dòng)詳情可了解哦~
掃描關(guān)注“慧聚IT”微信公眾號(hào),及時(shí)獲取更多產(chǎn)品最新動(dòng)態(tài)及最新資訊
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn