フォームフィールドの移動と削除

既存のPDFファイル内のフォームフィールドを新しい場所に移動する

フォームフィールドを新しい場所に移動したい場合は、FormEditorクラスのMoveFieldメソッドを使用できます。このメソッドには、フィールド名とこのフィールドの新しい位置を提供するだけで済みます。また、FormEditorクラスのSaveメソッドを使用して、更新されたPDFファイルを保存する必要があります。以下のコードスニペットは、PDFファイル内でフォームフィールドを新しい場所に移動する方法を示しています。

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void MoveField()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
    using (var editor = new Aspose.Pdf.Facades.FormEditor())
    {
        // Bind PDF document
        editor.BindPdf(dataDir + "MoveField.pdf");
        editor.MoveField("textbox1", 262.56f, 496.75f, 382.28f, 514.03f);
        // Save PDF document
        editor.Save(dataDir + "MoveField_out.pdf");
    }
}

既存のPDFファイルからフォームフィールドを削除する

既存のPDFファイルからフォームフィールドを削除するには、FormEditorクラスのRemoveFieldメソッドを使用できます。このメソッドは、フィールド名という1つの引数のみを取ります。FormEditorクラスのオブジェクトを作成し、特定のフィールドをPDFから削除するためにRemoveFieldメソッドを呼び出し、その後、更新されたPDFファイルを保存するためにSaveメソッドを呼び出す必要があります。以下のコードスニペットは、既存のPDFファイルからフォームフィールドを削除する方法を示しています。

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void RemoveFields()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
    using (var editor = new Aspose.Pdf.Facades.FormEditor())
    {
        // Bind PDF document
        editor.BindPdf(dataDir + "ModifyFormField.pdf");
        editor.RemoveField("textbox1");
        // Save PDF document
        editor.Save(dataDir + "RemoveField_out.pdf");
    }
}

PDF内のフォームフィールドの名前を変更する

また、FormEditorクラスのRenameFieldメソッドを使用してフィールドの名前を変更することもできます。

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void RenameFields()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
    using (var editor = new Aspose.Pdf.Facades.FormEditor())
    {
        // Bind PDF document
        editor.BindPdf(dataDir + "ModifyFormField.pdf");
        editor.RenameField("textbox1", "FirstName");
        // Save PDF document
        editor.Save(dataDir + "RenameField_out.pdf");
    }
}