Apparence et attributs des champs

Détails de mise en œuvre

La méthode SetFieldAppearance est utilisée pour changer l’apparence d’un champ de formulaire. Elle prend AnnotationFlag comme paramètre. AnnotationFlag est une énumération qui a différents membres comme Hidden ou NoRotate, etc.

La méthode SetFieldAttributes est utilisée pour changer l’attribut d’un champ de formulaire. Un paramètre passé à cette méthode est l’énumération PropertyFlag qui contient des membres comme ReadOnly ou Required, etc.

La classe FormEditor fournit également une méthode pour définir la limite du champ. Elle indique au champ combien de caractères il peut contenir. Le code ci-dessous montre comment toutes ces méthodes peuvent être utilisées.

 // 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");
         }
     }
 }