只需幾個步驟,即可使用 IronPDF 填寫並編輯 PDF 表單。 本指南將示範如何定位表單欄位、修改其值,以及儲存更新後的文件。 非常適合將 PDF 表單編輯功能無縫整合至您的 C# 應用程式中。
1Install IronPDF with NuGet Package Manager
PM > Install-Package IronPdf
Install-Package IronPdf
2複製並運行這段程式碼片段。
var pdf = IronPdf.PdfDocument.FromFile("form.pdf");var field = pdf.Form.FindFormField("nameField");field.Value = "John Doe";pdf.SaveAs("updated_form.pdf");
var pdf = IronPdf.PdfDocument.FromFile("form.pdf");
var field = pdf.Form.FindFormField("nameField");
field.Value = "John Doe";
pdf.SaveAs("updated_form.pdf");
Dim pdf = IronPdf.PdfDocument.FromFile("form.pdf")Dim field = pdf.Form.FindFormField("nameField")field.Value = "John Doe"pdf.SaveAs("updated_form.pdf")
Dim pdf = IronPdf.PdfDocument.FromFile("form.pdf")
Dim field = pdf.Form.FindFormField("nameField")
field.Value = "John Doe"
pdf.SaveAs("updated_form.pdf")
IronPDF 可輕鬆編輯 PDF 文件中各類現有表單欄位。 無論是自動化文件工作流程、建立批量表單提交,還是開發互動式 PDF 應用程式,IronPDF 的表單編輯功能都能提供您所需的靈活性與控制力。 此函式庫支援所有標準的 PDF 表單欄位型別,並能與現有的 .NET 應用程式無縫整合,使其成為企業文件管理系統的理想選擇。
對於需要數位簽名的複雜表單,IronPDF 提供表單編輯與文件簽署工作流程之間的無縫整合。 您亦可設定 PDF 密碼與權限,以防止已編輯的表單遭到未經授權的修改。
如何填寫文字區塊和輸入表單?
若要編輯文字區塊和輸入表單,請將 Value 屬性指派給所需資訊。 以下程式碼首先使用 FindFormField 方法並傳入表單名稱,來尋找表單物件。 接著,它會存取並設定該物件的 Value 屬性。 此方法適用於所有文字型態的表單欄位,包括單行輸入欄位及多行文字區塊。
using IronPdf;PdfDocument pdf = PdfDocument.FromFile("textAreaAndInputForm.pdf");// Set text input form valuespdf.Form.FindFormField("firstname").Value = "John";pdf.Form.FindFormField("lastname").Value = "Smith";// Set text area form valuespdf.Form.FindFormField("address").Value = "Iron Software LLC\r\n205 N. Michigan Ave.";pdf.SaveAs("textAreaAndInputFormEdited.pdf");
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");
ImportsIronPdfDim pdf AsPdfDocument = PdfDocument.FromFile("textAreaAndInputForm.pdf")' Set text input form valuespdf.Form.FindFormField("firstname").Value = "John"pdf.Form.FindFormField("lastname").Value = "Smith"' Set text area form valuespdf.Form.FindFormField("address").Value = "Iron Software LLC" & vbCrLf & "205 N. Michigan Ave."pdf.SaveAs("textAreaAndInputFormEdited.pdf")
Imports IronPdf
Dim 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")
請注意,在填寫多行文字區塊時,可使用 \r\n 進行換行,以正確格式化網址、註解或其他多行內容。 表單欄位會根據原始 PDF 中定義的欄位尺寸,自動處理文字換行。
編輯後的文字呈現形式為何?
如何更新核取方塊和下拉式選單?
編輯現有的核取方塊和下拉式選單表單時,請先根據欄位名稱查找該表單欄位。 將 Value 屬性設為 'Yes',即可勾選此核取方塊。 請透過將所需選項指派給其 Value 屬性,從下拉式選單中選取任何可用選項。 為方便起見,請透過存取 Choices 屬性來取得所有選項值。
了解如何操作這些互動式表單元件,對於建置動態 PDF 應用程式至關重要。 若您需要從頭開始建立 PDF 表單,IronPDF 提供全面的工具,讓您能在文件中新增核取方塊、下拉式選單及其他表單元件。
using IronPdf;using System;PdfDocument pdf = PdfDocument.FromFile("checkboxAndComboboxForm.pdf");var checkboxForm = pdf.Form.FindFormField("taskCompleted");// Check the checkbox formcheckboxForm.Value = "Yes";var comboboxForm = pdf.Form.FindFormField("priority");// Set the combobox valuecomboboxForm.Value = "Low";// Print out all the available choicesforeach (var choice in comboboxForm.Choices){Console.WriteLine(choice);}pdf.SaveAs("checkboxAndComboboxFormEdited.pdf");
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");
ImportsIronPdfImportsSystemPrivate pdf AsPdfDocument = PdfDocument.FromFile("checkboxAndComboboxForm.pdf")Private checkboxForm = pdf.Form.FindFormField("taskCompleted")' Check the checkbox formcheckboxForm.Value = "Yes"Dim comboboxForm = pdf.Form.FindFormField("priority")' Set the combobox valuecomboboxForm.Value = "Low"' Print out all the available choicesFor Each choice In comboboxForm.ChoicesConsole.WriteLine(choice)Next choicepdf.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")
using IronPdf;using System;PdfDocument pdf = PdfDocument.FromFile("radioButtomForm.pdf");var radioForm = pdf.Form.FindFormField("traveltype");// Set the radio button valueradioForm.Value = "Airplane";// Print out all the available choicesforeach(var annotation in radioForm.Annotations){Console.WriteLine(annotation.OnAppearance);}pdf.SaveAs("radioButtomFormEdited.pdf");
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");
ImportsIronPdfImportsSystemPrivate pdf AsPdfDocument = PdfDocument.FromFile("radioButtomForm.pdf")Private radioForm = pdf.Form.FindFormField("traveltype")' Set the radio button valueradioForm.Value = "Airplane"' Print out all the available choicesFor Each annotation In radioForm.AnnotationsConsole.WriteLine(annotation.OnAppearance)Next annotationpdf.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")
移除表單欄位後,您可能希望將 PDF 文件儲存並匯出為各種格式。 IronPDF 支援多種匯出選項,包括儲存至磁碟、記憶體流,或透過網頁應用程式直接提供 PDF 檔案。
using IronPdf;using IronSoftware.Forms;PdfDocument pdf = PdfDocument.FromFile("textAreaAndInputForm.pdf");// Remove FormIFormField targetForm = pdf.Form.FindFormField("firstname");pdf.Form.Remove(targetForm);pdf.SaveAs("removedForm.pdf");
using IronPdf;
using IronSoftware.Forms;
PdfDocument pdf = PdfDocument.FromFile("textAreaAndInputForm.pdf");
// Remove Form
IFormField targetForm = pdf.Form.FindFormField("firstname");
pdf.Form.Remove(targetForm);
pdf.SaveAs("removedForm.pdf");
IronPDF allows you to implement security measures such as encrypting documents and setting permissions, helping to protect form data throughout its lifecycle within your application.
Is IronPDF suitable for creating fully interactive PDF applications in .NET?
Yes, IronPDF integrates into .NET projects, making it ideal for building interactive PDF applications with features that support all standard form field types and customizable PDF functionalities.
What is the recommended method for filling PDF forms with IronPDF?
The recommended method involves downloading IronPDF, loading the PDF with `FromFile`, modifying form fields using `FindFormField` and setting their `Value`, then saving the document with `SaveAs`.
How does IronPDF handle multiline text areas in forms?
For multiline text areas, IronPDF allows you to use '\r\n' for line breaks, ensuring the text wraps correctly based on the field dimensions in the original PDF.