GetListField() public méthode

public GetListField ( ) : PdfFormField
Résultat PdfFormField
        private void VisibleTopChoiceHelper(int topVisible, int expected, String file) {
            Document document = new Document();
            FileStream fos = new FileStream(OUTPUT_FOLDER + file, FileMode.Create);
            PdfWriter writer = PdfWriter.GetInstance(document, fos);
            document.Open();

            TextField textField = new TextField(writer, new Rectangle(380, 560, 500, 610), "testListBox");

            textField.Visibility = BaseField.VISIBLE;
            textField.Rotation = 0;

            textField.FontSize = 14f;
            textField.TextColor = BaseColor.MAGENTA;

            textField.BorderColor = BaseColor.BLACK;
            textField.BorderStyle = PdfBorderDictionary.STYLE_SOLID;

            textField.Font = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED);
            textField.BorderWidth = BaseField.BORDER_WIDTH_THIN;

            writer.RunDirection = PdfWriter.RUN_DIRECTION_LTR;

            textField.Choices = new String[] {"one", "two", "three"};
            textField.ChoiceExports = new String[] {"1", "2", "3"};

            //choose the second item
            textField.ChoiceSelection = 1;
            //set the first item as the visible one
            textField.VisibleTopChoice = topVisible;

            Assert.AreEqual(expected, textField.VisibleTopChoice);

            PdfFormField field = textField.GetListField();

            writer.AddAnnotation(field);

            document.Close();

            // compare
            CompareTool compareTool = new CompareTool();
            String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER + file, CMP_FOLDER + file, OUTPUT_FOLDER, "diff");
            if (errorMessage != null) {
                Assert.Fail(errorMessage);
            }
        }
Exemple #2
0
// ---------------------------------------------------------------------------
    public void CellLayout(PdfPCell cell, Rectangle rectangle, 
        PdfContentByte[] canvases) 
    {
      PdfWriter writer = canvases[0].PdfWriter;
      TextField text = new TextField(
        writer, rectangle, string.Format("choice_{0}", cf)
      );
      text.BackgroundColor = new GrayColor(0.75f);
      switch(cf) {
        case 1:
          text.Choices = LANGUAGES;
          text.ChoiceExports = EXPORTVALUES;
          text.ChoiceSelection = 2;
          writer.AddAnnotation(text.GetListField());
          break;
        case 2:
          text.Choices = LANGUAGES;
          text.BorderColor = BaseColor.GREEN;
          text.BorderStyle = PdfBorderDictionary.STYLE_DASHED;
          text.Options = TextField.MULTISELECT;
          List<int> selections = new List<int>();
          selections.Add(0);
          selections.Add(2);
          text.ChoiceSelections = selections;
          PdfFormField field = text.GetListField();
          writer.AddAnnotation(field);
          break;
        case 3:
          text.BorderColor = BaseColor.RED;
          text.BackgroundColor = BaseColor.GRAY;
          text.Choices = LANGUAGES;
          text.ChoiceExports = EXPORTVALUES;
          text.ChoiceSelection = 4;
          writer.AddAnnotation(text.GetComboField());
          break;
        case 4:
          text.Choices = LANGUAGES;
          text.Options = TextField.EDIT;
          writer.AddAnnotation(text.GetComboField());
          break;
      }
    }