Bekerja dengan Item Daftar

Tambahkan Item Daftar di File PDF yang Ada

AddListItem metode memungkinkan Anda untuk menambahkan item di bidang ListBox. Argumen pertama adalah nama bidang dan argumen kedua adalah item bidang. Anda dapat melewatkan satu item bidang atau Anda dapat melewatkan array string yang berisi daftar item. Metode ini disediakan oleh kelas FormEditor. Cuplikan kode berikut menunjukkan cara menambahkan item daftar di file PDF.

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

     // Create an instance of FormEditor to manipulate form fields
     using (var formEditor = new Aspose.Pdf.Facades.FormEditor())
     {
         // Bind PDF document
         formEditor.BindPdf(dataDir + "Sample-Form-01.pdf");

         // Add a ListBox field for selecting country, placed at the specified coordinates on page 1
         formEditor.AddField(Aspose.Pdf.Facades.FieldType.ListBox, "Country", 1, 232.56f, 476.75f, 352.28f,
             514.03f);

         // Add list items to the 'Country' ListBox field
         formEditor.AddListItem("Country", "USA");
         formEditor.AddListItem("Country", "Canada");
         formEditor.AddListItem("Country", "France");
         formEditor.AddListItem("Country", "Spain");

         // Save PDF document
         formEditor.Save(dataDir + "Sample-Form-01-mod.pdf");
     }
 }

Hapus Item Daftar dari File PDF yang Ada

DelListItem metode memungkinkan Anda untuk menghapus item tertentu dari ListBox. Parameter pertama adalah nama bidang sementara parameter kedua adalah item yang ingin Anda hapus dari daftar. Metode ini disediakan oleh kelas FormEditor. Cuplikan kode berikut menunjukkan cara menghapus item daftar dari file PDF.

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

     // Create an instance of FormEditor to manipulate form fields
     using (var formEditor = new Aspose.Pdf.Facades.FormEditor())
     {
         // Bind PDF document
         formEditor.BindPdf(dataDir + "Sample-Form-04.pdf");

         // Delete the list item "France" from the 'Country' ListBox field
         formEditor.DelListItem("Country", "France");

         // Save PDF document
         formEditor.Save(dataDir + "Sample-Form-04-mod.pdf");
     }
 }