Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
既存のPDFファイルにフォームフィールドを追加するには、FormEditorクラスのAddFieldメソッドを使用する必要があります。このメソッドでは、追加したいフィールドのタイプとフィールドの名前および位置を指定する必要があります。FormEditorクラスのオブジェクトを作成し、AddFieldメソッドを使用してPDFに新しいフィールドを追加します。また、SetFieldLimitを使用してフィールド内の文字数の制限を指定し、最後にSaveメソッドを使用して更新されたPDFファイルを保存します。以下のコードスニペットは、既存のPDFファイルにフォームフィールドを追加する方法を示しています。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddField()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Create an instance of FormEditor to manipulate form fields
using (var editor = new Aspose.Pdf.Facades.FormEditor())
{
// Bind PDF document
editor.BindPdf(dataDir + "Sample-Form-01.pdf");
// Add a text field named "Country" to the first page of the PDF
// Specify the coordinates of the field (left, bottom, right, top)
editor.AddField(Aspose.Pdf.Facades.FieldType.Text, "Country", 1, 232.56f, 496.75f, 352.28f, 514.03f);
// Set a character limit for the "Country" field to 20 characters
editor.SetFieldLimit("Country", 20);
// Save PDF document
editor.Save(dataDir + "Sample-Form-01-mod.pdf");
}
}
AddSubmitBtnメソッドを使用すると、PDFファイル内の送信ボタンのURLを設定できます。これは、送信ボタンがクリックされたときにデータが送信されるURLです。例のコードでは、URL、フィールドの名前、追加したいページ番号、およびボタンの配置座標を指定します。AddSubmitBtnメソッドには、送信ボタンフィールドの名前とURLが必要です。このメソッドはFormEditorクラスによって提供されます。以下のコードスニペットは、送信ボタンのURLを設定する方法を示しています。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddSubmitBtn()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Create an instance of FormEditor to manipulate form fields
using (var editor = new Aspose.Pdf.Facades.FormEditor())
{
// Bind PDF document
editor.BindPdf(dataDir + "Sample-Form-01.pdf");
// Add a submit button named "Submit" to the first page of the PDF
// Specify the button text ("Submit"), the URL to which the form data will be submitted,
// and the coordinates of the button (left, bottom, right, top)
editor.AddSubmitBtn("Submit", 1, "Submit", "http://localhost:3000", 232.56f, 466.75f, 352.28f, 484.03f);
// Save PDF document
editor.Save(dataDir + "Sample-Form-01-mod.pdf");
}
}
AddFieldScriptメソッドを使用すると、PDFファイル内のプッシュボタンにJavaScriptを追加できます。このメソッドでは、プッシュボタンの名前とJavaScriptが必要です。このメソッドはFormEditorクラスによって提供されます。以下のコードスニペットは、プッシュボタンにJavaScriptを設定する方法を示しています。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddFieldScript()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Create an instance of FormEditor to manipulate form fields
using (var editor = new Aspose.Pdf.Facades.FormEditor())
{
// Bind PDF document
editor.BindPdf(dataDir + "Sample-Form-01.pdf");
// Add a JavaScript action to the field named "Last Name"
// The script displays an alert box with the message "Only one last name"
editor.AddFieldScript("Last Name", "app.alert(\"Only one last name\",3);");
// Save PDF document
editor.Save(dataDir + "Sample-Form-01-mod.pdf");
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.