VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
Vintasoft.Imaging.Pdf.Tree.InteractiveForms Namespace / PdfInteractiveFormTextField Class / Value Property
Синтаксис Ремарки Example Требования Смотрите также
В этом разделе
    Value Свойство (PdfInteractiveFormTextField)
    В этом разделе
    Возвращает или устанавливает значение текстового поля.
    Синтаксис
    Ремарки

    Это свойство наследуется.

    Пример

    Вот пример, показывающий, как создать PDF документ с числовым текстовым полем:

    
    Class PdfInteractiveFormTextFieldExample
        ''' <summary>
        ''' Creates a PDF document with numeric text field.
        ''' </summary>
        ''' <param name="filename">The filename.</param>
        Public Shared Sub CreateDocumentWithNumericTextField(filename As String)
            ' create PDF document
            Using document As New Vintasoft.Imaging.Pdf.PdfDocument()
                ' create interactive form in PDF document
                document.InteractiveForm = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document)
    
                ' specify that the viewer application must construct appearance streams and
                ' appearance properties for all widget annotations
                document.InteractiveForm.NeedAppearances = True
    
                ' create an empty page
                Dim page As New Vintasoft.Imaging.Pdf.Tree.PdfPage(document, Vintasoft.Imaging.PaperSizeKind.A4)
                ' add page to the document
                document.Pages.Add(page)
    
                Dim width As Single = 100
                Dim height As Single = 25
                ' create a rectangle that defines the field position on PDF page
                Dim rect As New System.Drawing.RectangleF((page.Size.Width - width) / 2, ((page.Size.Height - height) / 3) * 2, width, height)
    
                ' create a text field
                Dim textField As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField(document, "NumericField", rect, "12345")
    
                ' create the text value validation method that accepts numbers (0-9 digits) only
                Dim javaScriptCode As String = "var regex = /[^0-9]/;if(regex.test(event.change)) event.change = '';"
                Dim action As New Vintasoft.Imaging.Pdf.Tree.PdfJavaScriptAction(document, javaScriptCode)
                textField.AdditionalActions = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormFieldAdditionalActions(document)
                ' set the validation action for the AdditionalActions.Keystroke trigger event
                textField.AdditionalActions.Keystroke = action
    
                ' set the default appearance of text
                Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
                textField.SetTextDefaultAppearance(font, 12, System.Drawing.Color.Black)
    
                ' set the border style
                textField.Annotation.BorderStyle = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document)
                textField.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Inset
                textField.Annotation.BorderStyle.Width = 1
    
                ' set the appearance characteristics
                textField.Annotation.AppearanceCharacteristics = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document)
                textField.Annotation.AppearanceCharacteristics.BorderColor = System.Drawing.Color.Gray
    
                ' add the text field to the interactive form of document
                document.InteractiveForm.Fields.Add(textField)
    
                ' add annotation, associated with the text field, to the page
                page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
                page.Annotations.Add(textField.Annotation)
    
                ' save the document
                document.Save(filename)
            End Using
        End Sub
    End Class
    
    
    
    class PdfInteractiveFormTextFieldExample
    {
        /// <summary>
        /// Creates a PDF document with numeric text field.
        /// </summary>
        /// <param name="filename">The filename.</param>
        public static void CreateDocumentWithNumericTextField(string filename)
        {
            // create PDF document
            using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument())
            {
                // create interactive form in PDF document
                document.InteractiveForm = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document);
    
                // specify that the viewer application must construct appearance streams and
                // appearance properties for all widget annotations
                document.InteractiveForm.NeedAppearances = true;
    
                // create an empty page
                Vintasoft.Imaging.Pdf.Tree.PdfPage page = new Vintasoft.Imaging.Pdf.Tree.PdfPage(
                    document, Vintasoft.Imaging.PaperSizeKind.A4);
                // add page to the document
                document.Pages.Add(page);
    
                float width = 100;
                float height = 25;
                // create a rectangle that defines the field position on PDF page
                System.Drawing.RectangleF rect = new System.Drawing.RectangleF(
                    (page.Size.Width - width) / 2,
                    ((page.Size.Height - height) / 3) * 2,
                    width, height);
    
                // create a text field
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField textField =
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField(
                        document, "NumericField", rect, "12345");
    
                // create the text value validation method that accepts numbers (0-9 digits) only
                string javaScriptCode = 
                    "var regex = /[^0-9]/;if(regex.test(event.change)) event.change = '';";
                Vintasoft.Imaging.Pdf.Tree.PdfJavaScriptAction action = 
                    new Vintasoft.Imaging.Pdf.Tree.PdfJavaScriptAction(document, javaScriptCode);
                textField.AdditionalActions = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormFieldAdditionalActions(document);
                // set the validation action for the AdditionalActions.Keystroke trigger event
                textField.AdditionalActions.Keystroke = action;
    
                // set the default appearance of text
                Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font = document.FontManager.GetStandardFont(
                    Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
                textField.SetTextDefaultAppearance(font, 12, System.Drawing.Color.Black);
    
                // set the border style
                textField.Annotation.BorderStyle = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document);
                textField.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Inset;
                textField.Annotation.BorderStyle.Width = 1;
                
                // set the appearance characteristics
                textField.Annotation.AppearanceCharacteristics = 
                    new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document);
                textField.Annotation.AppearanceCharacteristics.BorderColor = System.Drawing.Color.Gray;
    
                // add the text field to the interactive form of document
                document.InteractiveForm.Fields.Add(textField);
    
                // add annotation, associated with the text field, to the page
                page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
                page.Annotations.Add(textField.Annotation);
    
                // save the document
                document.Save(filename);
            }
        }
    }
    
    

    Требования

    Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также