字段外观和属性

Contents
[ ]

实现细节

SetFieldAppearance 方法用于更改表单字段的外观。它接受 AnnotationFlag 作为参数。AnnotationFlag 是一个枚举,具有不同的成员,如 Hidden 或 NoRotate 等。

SetFieldAttributes 方法用于更改表单字段的属性。传递给此方法的参数是 PropertyFlag 枚举,其中包含 ReadOnly 或 Required 等成员。

FormEditor 类还提供了一个方法来设置字段限制。它告诉字段可以填充多少个字符。下面的代码片段展示了如何使用这些方法。

 // For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
 private static void AddFieldAndSetAttributes()
 {
     // The path to the documents directory
     var dataDir = RunExamples.GetDataDir_AsposePdf();

     // Open PDF document
     using (var doc = new Aspose.Pdf.Document(dataDir + "FilledForm.pdf"))
     {
         // Create an instance of FormEditor to manipulate form fields
         using (var formEditor = new Aspose.Pdf.Facades.FormEditor(doc))
         {
             // Add a new text field to the form on page 1 at the specified coordinates and size
             formEditor.AddField(Aspose.Pdf.Facades.FieldType.Text, "text1", 1, 200, 550, 300, 575);

             // Set the field attribute to make the text field required (user must fill it)
             formEditor.SetFieldAttribute("text1", Aspose.Pdf.Facades.PropertyFlag.Required);

             // Set a character limit for the field (maximum 20 characters)
             formEditor.SetFieldLimit("text1", 20);

             // Save PDF document
             formEditor.Save(dataDir + "ChangingFieldAppearance_out.pdf");
         }
     }
 }