如何填寫和編輯 PDF 表單
IronPDF提供直觀的工具集來編輯PDF文件中的現有表單,包括文字區域、文字輸入、複選框、下拉選單和選擇按鈕。
如何填寫和編輯 PDF 表單
- 下載用於填寫和編輯 PDF 表單的 C# 程式庫
- 使用以下方式匯入目標 PDF 文件
從文件
方法 - 找到要修改的表單對象,使用
查找表單欄位
方法 - 修改 價值 設定所需訊息的屬性
- 匯出編輯後的 PDF 文件
立即開始在您的專案中使用IronPDF,並享受免費試用。
查看 IronPDF 上 Nuget 快速安裝和部署。已被下載超過800萬次,它正用C#改變PDF。
Install-Package IronPdf
請考慮安裝 IronPDF DLL 直接下載並手動安裝到您的專案或GAC表單: IronPdf.zip
手動安裝到您的項目中
下載DLL編輯表單
IronPDF 輕鬆編輯 PDF 文件中的各種類型現有表單欄位。
文本區域和輸入表單
要編輯文本區域和輸入表單,請將 Value 屬性指定為所需的信息。以下代碼首先使用 FindFormField
方法根據表單名稱找到表單對象。然後,它訪問並分配對象的 Value 屬性。
:path=/static-assets/pdf/content-code-examples/how-to/edit-forms-input-textarea.cs
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("textAreaAndInputForm.pdf");
// Set text input form values
pdf.Form.FindFormField("firstname").Value = "John";
pdf.Form.FindFormField("lastname").Value = "Smith";
// Set text area form values
pdf.Form.FindFormField("address").Value = "Iron Software LLC\r\n205 N. Michigan Ave.";
pdf.SaveAs("textAreaAndInputFormEdited.pdf");
Imports Microsoft.VisualBasic
Imports IronPdf
Private pdf As PdfDocument = PdfDocument.FromFile("textAreaAndInputForm.pdf")
' Set text input form values
pdf.Form.FindFormField("firstname").Value = "John"
pdf.Form.FindFormField("lastname").Value = "Smith"
' Set text area form values
pdf.Form.FindFormField("address").Value = "Iron Software LLC" & vbCrLf & "205 N. Michigan Ave."
pdf.SaveAs("textAreaAndInputFormEdited.pdf")
輸出 PDF 文件
复选框和组合框表单
通過首先根據名稱找到表單字段來編輯現有的複選框和組合框表單。將 Value 屬性分配為 'Yes' 以檢查複選框表單。在組合框中選擇任意可用選項,將所需選項分配給 Value 屬性。為了方便起見,可以通過訪問 Choices 屬性來檢索所有選項的值。
:path=/static-assets/pdf/content-code-examples/how-to/edit-forms-checkbox-combobox.cs
using IronPdf;
using System;
PdfDocument pdf = PdfDocument.FromFile("checkboxAndComboboxForm.pdf");
var checkboxForm = pdf.Form.FindFormField("taskCompleted");
// Check the checkbox form
checkboxForm.Value = "Yes";
var comboboxForm = pdf.Form.FindFormField("priority");
// Set the combobox value
comboboxForm.Value = "Low";
// Print out all the available choices
foreach (var choice in comboboxForm.Choices)
{
Console.WriteLine(choice);
}
pdf.SaveAs("checkboxAndComboboxFormEdited.pdf");
Imports IronPdf
Imports System
Private pdf As PdfDocument = PdfDocument.FromFile("checkboxAndComboboxForm.pdf")
Private checkboxForm = pdf.Form.FindFormField("taskCompleted")
' Check the checkbox form
checkboxForm.Value = "Yes"
Dim comboboxForm = pdf.Form.FindFormField("priority")
' Set the combobox value
comboboxForm.Value = "Low"
' Print out all the available choices
For Each choice In comboboxForm.Choices
Console.WriteLine(choice)
Next choice
pdf.SaveAs("checkboxAndComboboxFormEdited.pdf")
輸出 PDF 文件
單選按鈕表單
在 IronPDF 中使用單選按鈕表單時,同一組的單選按鈕包含在一個表單物件中。若要編輯單選按鈕的值,只需將表單物件的 Value 屬性分配給其中一個可用選項。使用 Annotations 屬性檢索所有可用選項。以下代碼演示如何編輯單選按鈕的值。
:path=/static-assets/pdf/content-code-examples/how-to/edit-forms-radiobutton.cs
using IronPdf;
using System;
PdfDocument pdf = PdfDocument.FromFile("radioButtomForm.pdf");
var radioForm = pdf.Form.FindFormField("traveltype");
// Set the radio button value
radioForm.Value = "Airplane";
// Print out all the available choices
foreach(var annotation in radioForm.Annotations)
{
Console.WriteLine(annotation.OnAppearance);
}
pdf.SaveAs("radioButtomFormEdited.pdf");
Imports IronPdf
Imports System
Private pdf As PdfDocument = PdfDocument.FromFile("radioButtomForm.pdf")
Private radioForm = pdf.Form.FindFormField("traveltype")
' Set the radio button value
radioForm.Value = "Airplane"
' Print out all the available choices
For Each annotation In radioForm.Annotations
Console.WriteLine(annotation.OnAppearance)
Next annotation
pdf.SaveAs("radioButtomFormEdited.pdf")
此外,使用 Clear
方法取消選擇單選按鈕。該方法僅在對象類型為 RadioFormField 時才可訪問。從 PDF 中訪問單選表單對象後,可以將其轉換為 RadioFormField 類型。
輸出 PDF 文件
了解如何在以下文章中以程式化方式建立 PDF 表單:如何建立 PDF 表單.