PDFフォームの記入および編集方法
IronPDFは、PDFドキュメント内の既存のフォームを編集するための直感的なツールセットを提供しており、テキストエリア、テキスト入力、チェックボックス、コンボボックス、ラジオボタンを含みます。
IronPDFを始めましょう
今日から無料トライアルでIronPDFをあなたのプロジェクトで使い始めましょう。
PDFフォームの記入および編集方法
- PDFフォームの入力と編集のためのC#ライブラリをダウンロード
- 対象のPDFドキュメントをインポートするには
ファイルから
メソッド - フォームオブジェクトを修正するには、以下を使用して見つけます
FindFormField
メソッド - 「修正する」 価値 希望する情報を設定するためのプロパティ
- 編集した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")
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プロパティに利用可能な選択肢の1つを割り当てるだけです。 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からフォームを削除するには、まず FindFormField
メソッドを使用して対象のフォームを選択します。 フォームオブジェクトをForm.Remove
メソッドに渡します。これはPdfDocumentオブジェクトからアクセスできます。 このメソッドを私たちの上で試してみましょうtextAreaAndInputForm.pdfファイル。
: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")
PDFドキュメント出力
以下の記事でプログラムによってPDFフォームを作成する方法を学びましょう:PDFフォームの作成方法."