VintaSoft Imaging .NET SDK 14.1: Документация для .NET разработчика
Vintasoft.Imaging.Pdf.Tree.InteractiveForms Namespace / PdfInteractiveFormCheckBoxField Class
    Класс PdfInteractiveFormCheckBoxField
    Предоставляет информацию о поле интерактивной формы, которое определяет флажок.
    Объектная модель
    PdfFont PdfInteractiveFormFieldAdditionalActions PdfInteractiveFormField PdfWidgetAnnotation PdfInteractiveFormFieldList PdfDocument PdfIndirectReference PdfBasicObject PdfInteractiveFormCheckBoxField
    Синтаксис
    'Declaration
    
    Public Class PdfInteractiveFormCheckBoxField
       Inherits PdfInteractiveFormSwitchableButtonField
    
    
     
    Ремарки

    Поле флажка представляет собой один или несколько флажков, которые переключаются между двумя состояниями: включенным и выключенным, при управлении пользователем с помощью мыши или клавиатуры. Каждое состояние может иметь отдельный внешний вид, который определяется потоком внешнего вида во внешнем виде Widget-аннотации поля.
    Внешний вид выключенного состояния не является обязательным, но, если он присутствует, его необходимо сохранить в словаре внешнего вида под именем "Выключено". Рекомендуемое (но не обязательное) имя для включенного состояния - "Да".
    Чтобы изменить значение поля, используйте свойство Value. Чтобы изменить значение поля по умолчанию, используйте свойство DefaultValue.

    Пример

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

    Class PdfInteractiveFormCheckBoxFieldExample
        ''' <summary>
        ''' Creates a PDF document with the check box fields.
        ''' </summary>
        ''' <param name="filename">The filename.</param>
        Public Shared Sub CreateDocumentWithCheckBoxField(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 fontSize As Single = 20
                Dim width As Single = fontSize * 3F / 2F
                Dim height As Single = width
                ' create a rectangle that defines check box 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 the first check box
                Dim checkBox1 As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormCheckBoxField(document, "CheckBox1", rect)
                ' create a rectangle that defines size of the check box content
                Dim contentRect As New System.Drawing.RectangleF(0, 0, rect.Width, rect.Height)
                ' get a reference to "ZapfDingbats" font
                Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.ZapfDingbats)
                ' create "Yes" appearance of checkbox1
                Using g As Vintasoft.Imaging.Pdf.Drawing.PdfGraphics = checkBox1.CreateYesAppearanceGraphics()
                    g.DrawString("o", font, fontSize, New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black), contentRect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, _
                        False)
                    g.DrawString("4", font, fontSize, New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Green), contentRect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, _
                        False)
                End Using
                ' create "Off" appearance of checkbox1
                Using g As Vintasoft.Imaging.Pdf.Drawing.PdfGraphics = checkBox1.CreateOffAppearanceGraphics()
                    g.DrawString("o", font, fontSize, New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black), contentRect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, _
                        False)
                End Using
                ' set value of checkbox1
                checkBox1.Value = "Off"
    
                ' change the vertical position of rectangle that defines check box position on PDF page
                rect.Y -= rect.Height
    
                ' create the second check box
                Dim checkBox2 As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormCheckBoxField(document, "CheckBox2", rect)
                ' use checkbox1 appearance as checkbox2 appearance
                checkBox2.Annotation.Appearances = checkBox1.Annotation.Appearances
                ' set value of checkBox2
                checkBox2.Value = "Yes"
    
                ' add the check box fields to the interactive form of document
                document.InteractiveForm.Fields.Add(checkBox1)
                document.InteractiveForm.Fields.Add(checkBox2)
    
                ' add annotations, associated with check box fields, to the page
                page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
                page.Annotations.Add(checkBox1.Annotation)
                page.Annotations.Add(checkBox2.Annotation)
    
                ' save the document
                document.Save(filename)
            End Using
        End Sub
    End Class
    
    
    class PdfInteractiveFormCheckBoxFieldExample
    {
        /// <summary>
        /// Creates a PDF document with the check box fields.
        /// </summary>
        /// <param name="filename">The filename.</param>
        public static void CreateDocumentWithCheckBoxField(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 fontSize = 20;
                float width = fontSize * 3f / 2f;
                float height = width;
                // create a rectangle that defines check box 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 the first check box
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormCheckBoxField checkBox1 = 
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormCheckBoxField(document, "CheckBox1", rect);
                // create a rectangle that defines size of the check box content
                System.Drawing.RectangleF contentRect = new System.Drawing.RectangleF(0, 0, rect.Width, rect.Height);
                // get a reference to "ZapfDingbats" font
                Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font = document.FontManager.GetStandardFont(
                    Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.ZapfDingbats);
                // create "Yes" appearance of checkbox1
                using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics g = checkBox1.CreateYesAppearanceGraphics())
                {
                    g.DrawString("o", font, fontSize, new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black), 
                        contentRect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, false);
                    g.DrawString("4", font, fontSize, new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Green), 
                        contentRect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, false);
                }
                // create "Off" appearance of checkbox1
                using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics g = checkBox1.CreateOffAppearanceGraphics())
                {
                    g.DrawString("o", font, fontSize, new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black), 
                        contentRect, Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Center, false);
                }
                // set value of checkbox1
                checkBox1.Value = "Off";
    
                // change the vertical position of rectangle that defines check box position on PDF page
                rect.Y -= rect.Height;
    
                // create the second check box
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormCheckBoxField checkBox2 =
                    new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormCheckBoxField(document, "CheckBox2", rect);
                // use checkbox1 appearance as checkbox2 appearance
                checkBox2.Annotation.Appearances = checkBox1.Annotation.Appearances;
                // set value of checkBox2
                checkBox2.Value = "Yes";
    
                // add the check box fields to the interactive form of document
                document.InteractiveForm.Fields.Add(checkBox1);
                document.InteractiveForm.Fields.Add(checkBox2);
    
                // add annotations, associated with check box fields, to the page
                page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
                page.Annotations.Add(checkBox1.Annotation);
                page.Annotations.Add(checkBox2.Annotation);
    
                // save the document
                document.Save(filename);
            }
        }
    }
    
    

    Иерархия наследования
    Требования

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

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