VintaSoft Imaging .NET SDK v8.7
Vintasoft.Imaging.Pdf.Tree.InteractiveForms Namespace / PdfInteractiveFormCheckBoxField Class
Members Example



In This Topic
    PdfInteractiveFormCheckBoxField Class
    In This Topic
    Provides information about interactive form field that defines check box.
    Object Model
    PdfInteractiveFormCheckBoxField ClassPdfInteractiveFormFieldAdditionalActions ClassPdfWidgetAnnotation ClassPdfBasicObject ClassPdfDocument ClassPdfFont ClassPdfIndirectReference ClassPdfInteractiveFormFieldList ClassPdfInteractiveFormField ClassPdfInteractiveFormField Class
    Syntax
    'Declaration
     
    Public Class PdfInteractiveFormCheckBoxField 
       Inherits PdfInteractiveFormSwitchableButtonField
    public class PdfInteractiveFormCheckBoxField : PdfInteractiveFormSwitchableButtonField 
    public __gc class PdfInteractiveFormCheckBoxField : public PdfInteractiveFormSwitchableButtonField 
    public ref class PdfInteractiveFormCheckBoxField : public PdfInteractiveFormSwitchableButtonField 
    Remarks
    A check box field represents one or more check boxes that toggle between two states, on and off, when manipulated by the user with the mouse or keyboard. Each state can have a separate appearance, which is defined by an appearance stream in the appearances of the field's widget annotation.
    The appearance for the off state is optional but, if present, must be stored in the appearance dictionary under the name "Off". The recommended (but not required) name for the on state is "Yes".
    To change value of the field, use property PdfInteractiveFormSwitchableButtonField.Value. To change default value of the field, use property PdfInteractiveFormSwitchableButtonField.DefaultValue.
    Example
    This example shows how to create a PDF document with the check box field:
    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);
            }
        }
    }
    Inheritance Hierarchy
    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also