FormSubmitSound.vb
''
'' This code is part of Document Solutions for PDF .NET demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Pdf.AcroForms
Imports GrapeCity.Documents.Pdf.Actions
Imports GrapeCity.Documents.Pdf.Annotations
Imports GrapeCity.Documents.Text
Imports System.Drawing
Imports System.IO

Public Class FormSubmitSound
    Public Function CreatePDF(ByVal stream As Stream) As Integer
        Dim doc = New GcPdfDocument()
        Dim page = doc.NewPage()

        Dim rc = Util.AddNote(
            "As in the 'Submit Form' sample, the Submit button's Activate is associated with ActionSubmitForm, " &
            "and the Reset button's Activate is associated with ActionResetForm. " &
            vbLf & "In addition to these handlers, in this sample the buttons' MouseDown events are associated with ActionSound, " &
            "so that the user gets appropriate audible feedback when clicking the button.",
            page)

        Dim g = page.Graphics
        Dim tf = New TextFormat() With {.Font = StandardFonts.Times, .FontSize = 14}
        Dim ip = New PointF(72, rc.Bottom + 36)
        Dim fldOffset As Single = 72 * 2 + 46
        Dim fldHeight As Single = tf.FontSize * 1.2F
        Dim dY As Single = 32

        '' Text field:
        g.DrawString("First name:", tf, ip)
        Dim fldFirstName = New TextField() With {.Name = "FirstName", .Value = "John"}
        fldFirstName.Widget.Page = page
        fldFirstName.Widget.Rect = New RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight)
        fldFirstName.Widget.DefaultAppearance.Font = tf.Font
        fldFirstName.Widget.DefaultAppearance.FontSize = tf.FontSize
        doc.AcroForm.Fields.Add(fldFirstName)
        ip.Y += dY

        '' Text field:
        g.DrawString("Last name:", tf, ip)
        Dim fldLastName = New TextField() With {.Name = "LastName", .Value = "Smith"}
        fldLastName.Widget.Page = page
        fldLastName.Widget.Rect = New RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight)
        fldLastName.Widget.DefaultAppearance.Font = tf.Font
        fldLastName.Widget.DefaultAppearance.FontSize = tf.FontSize
        doc.AcroForm.Fields.Add(fldLastName)
        ip.Y += dY

        '' Checkbox:
        g.DrawString("Subscribe to Mailing List:", tf, ip)
        Dim fldCheckbox = New CheckBoxField() With {.Name = "Subscribe", .Checked = True}
        fldCheckbox.Widget.Page = page
        fldCheckbox.Widget.Rect = New RectangleF(ip.X + fldOffset, ip.Y, fldHeight, fldHeight)
        doc.AcroForm.Fields.Add(fldCheckbox)
        ip.Y += dY

        '' Multiline TextBox:
        g.DrawString("Additional information:", tf, ip)
        Dim fldAdditionalInfo = New TextField() With {.Name = "AdditionalInfo", .Multiline = True}
        fldAdditionalInfo.Widget.Page = page
        fldAdditionalInfo.Widget.Rect = New RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight * 2)
        fldAdditionalInfo.Widget.DefaultAppearance.Font = tf.Font
        fldAdditionalInfo.Widget.DefaultAppearance.FontSize = tf.FontSize
        doc.AcroForm.Fields.Add(fldAdditionalInfo)
        ip.Y += dY * 2

        '' Submit form button:
        Dim btnSubmit = New PushButtonField()
        btnSubmit.Widget.Rect = New RectangleF(ip.X + fldOffset, ip.Y, 72, fldHeight)
        btnSubmit.Widget.ButtonAppearance.Caption = "Submit"
        btnSubmit.Widget.Highlighting = HighlightingMode.Invert
        btnSubmit.Widget.Page = page
        '' The URL for the submission:
        btnSubmit.Widget.Activate = New ActionSubmitForm("/Samples/HandleFormSubmitFields")
        ' Also, associated the MouseDown event with a confirmation sound:
        btnSubmit.Widget.Events.MouseDown = New ActionSound(SoundObject.FromFile(Path.Combine("Resources", "Sounds", "form-submitted.wav")))
        doc.AcroForm.Fields.Add(btnSubmit)

        '' Reset form button:
        Dim btnReset = New PushButtonField()
        btnReset.Widget.Rect = New RectangleF(ip.X + fldOffset + 72 * 1.5F, ip.Y, 72, fldHeight)
        btnReset.Widget.ButtonAppearance.Caption = "Reset"
        btnReset.Widget.Highlighting = HighlightingMode.Invert
        btnReset.Widget.Page = page
        ' Reset the form on button activation:
        btnReset.Widget.Activate = New ActionResetForm()
        ' Also, associated the MouseDown event with a confirmation sound:
        btnReset.Widget.Events.MouseDown = New ActionSound(SoundObject.FromFile(Path.Combine("Resources", "Sounds", "form-reset.wav")))
        doc.AcroForm.Fields.Add(btnReset)
        ip.Y += dY

        '' Done:
        doc.Save(stream)
        Return doc.Pages.Count
    End Function
End Class