How to Fill and Edit PDF Forms

This article was translated from English: Does it need improvement?
Translated
View the article in English
role="alert">您的公司每年在PDF安全性和合規性上的訂閱費用過高。考慮使用 IronSecureDoc,它提供數位簽章、編碼、加密和保護等SaaS服務的管理解決方案,僅需一次性付款即可。探索 IronSecureDoc 文件

IronPDF 提供了一套直觀的工具來編輯 PDF 文件中的現有表單,包括文本區域、文本輸入、複選框、下拉框和單選按鈕。

快速入門:使用 IronPDF 填寫 PDF 表單

只需幾個步驟,即可使用 IronPDF 輕鬆填寫和編輯 PDF 表單。 本快速指南演示如何找到表單字段、修改其值並保存更新的文件。 非常適合希望將 PDF 表單編輯無縫集成到其 C# 應用程序中的開發人員。

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

    var pdf = IronPdf.PdfDocument.FromFile("form.pdf");
    var field = pdf.Form.FindFormField("nameField");
    field.Value = "John Doe";
    pdf.SaveAs("updated_form.pdf");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer
class="hsg-featured-snippet">

最小工作流程(5 步)

  1. 下載用於填寫和編輯 PDF 表單的 C# 庫
  2. 使用 FromFile 方法導入目標 PDF 文件
  3. 使用 FindFormField 方法找到要修改的表單對象
  4. 修改 Value 屬性以設置所需的信息
  5. 導出已編輯的 PDF 文件

編輯表單

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")
$vbLabelText   $csharpLabel

輸出 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")
$vbLabelText   $csharpLabel

輸出 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")
$vbLabelText   $csharpLabel

此外,使用 Clear 方法取消選擇單選按鈕。 此方法僅能在對象類型為 RadioFormField 時訪問。 從 PDF 中訪問單選表單對象後,可以將其轉換為 RadioFormField 類型。

輸出 PDF 文件


刪除表單

要從 PDF 中刪除表單,首先使用 FindFormField 方法選擇目標表單。 將表單對象傳遞給 PdfDocument 對象中的 Form.Remove 方法。

:path=/static-assets/pdf/content-code-examples/how-to/edit-forms-remove-form.cs
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");
Imports IronPdf
Imports IronSoftware.Forms

Private pdf As PdfDocument = PdfDocument.FromFile("textAreaAndInputForm.pdf")

' Remove Form
Private targetForm As IFormField = pdf.Form.FindFormField("firstname")
pdf.Form.Remove(targetForm)

pdf.SaveAs("removedForm.pdf")
$vbLabelText   $csharpLabel

輸出 PDF 文件

在以下文章中了解如何以編程方式創建 PDF 表單:“如何創建 PDF 表單。”

準備看看您還能做哪些其他事情嗎? 查看我們的教程頁面:簽名和保護 PDF

常見問題解答

如何使用 C# 程式庫開始編輯 PDF 表單?

要開始使用 IronPDF 編輯 PDF 表單,首先需要從 NuGet 下載 C# 庫。然後,使用FromFile方法匯入 PDF 文檔,使用FindFormField找到表單字段,並根據需要修改Value屬性。

如何使用 C# 庫編輯 PDF 中的文字區域和輸入表單?

若要編輯文字區域和輸入表單,請使用FindFormField方法按名稱尋找表單欄位。然後,將所需值賦給 IronPDF 中表單欄位物件的Value屬性。

如何使用 C# 庫編輯 PDF 表單中的複選框和組合框?

若要編輯複選框,請將Value屬性設為「是」。對於組合框,請在使用FindFormField找到該欄位後,將所需的選項賦值給Value屬性。您可以使用 IronPDF 中的Choices屬性存取所有選項值。

如何使用 C# 庫編輯單選按鈕表單?

在 IronPDF 中,單選按鈕的編輯方法是將所需選項賦值給表單物件的Value屬性。使用Annotations屬性可以存取所有可用選項,而使用Clear方法可以取消選取單選按鈕。

如何使用 C# 函式庫從 PDF 中刪除表單?

若要從 PDF 中刪除表單,請使用FindFormField方法選擇表單字段,然後將字段物件傳遞給 IronPDF 中PdfDocument物件的Form.Remove方法。

能否使用 C# 庫來編輯任何類型的現有 PDF 表單欄位?

是的,IronPDF 可以編輯 PDF 文件中現有的表單字段,例如文字區域、文字輸入框、複選框、組合框和單選按鈕。

是否可以使用 C# 程式庫以程式設計方式建立 PDF 表單?

是的,您可以使用 IronPDF 以程式設計方式建立 PDF 表單。更多信息,請參閱文章“[如何建立 PDF 表單](/how-to/create-forms/)”。

文件管理解決方案還提供哪些其他功能?

IronSecureDoc 提供管理 SaaS 服務(如數位簽章、編輯、加密和保護)的解決方案,只需一次性付款即可享受所有這些服務。

如何使用 C# 修改表單欄位後匯出編輯後的 PDF?

使用 IronPDF 修改表單欄位後,可以使用PdfDocument物件的SaveAs方法將變更儲存回檔案系統,從而匯出編輯後的 PDF 文件。

我可以使用 C# 存取和編輯 PDF 組合框中的所有選項嗎?

是的,使用 IronPDF,您可以透過Choices屬性存取 PDF 組合框中的所有選項,並透過設定Value屬性來編輯所需的選項。

.NET 10 相容性:我可以使用 IronPDF 編輯面向 .NET 10 的 PDF 表單嗎?

是的——IronPDF 與 .NET 10 完全相容,因此您可以在 .NET 10 專案中使用相同的 API(如FindFormFieldFormPdfDocument )編輯 PDF 表單(包括尋找、變更和刪除表單欄位),而無需任何特殊的程式碼變更。

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'name'

Filename: sections/author_component.php

Line Number: 18

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 18
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'title'

Filename: sections/author_component.php

Line Number: 38

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 38
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'comment'

Filename: sections/author_component.php

Line Number: 48

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 48
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

準備好開始了嗎?
Nuget 下載 16,154,058 | 版本: 2025.11 剛剛發布