FormSubmit.vb
'' 完毕:
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Pdf.AcroForms
Imports GrapeCity.Documents.Pdf.Annotations
Imports GrapeCity.Documents.Pdf.Actions

'' 此示例演示如何创建用户可以提交的 AcroForm PDF。
'' 这里我们将其提交给示例服务器,示例服务器接收数据并将其发送回来
'' 以一种特殊的形式。
Public Class FormSubmit
    Function CreatePDF(ByVal stream As Stream) As Integer
        Dim doc = New GcPdfDocument()
        Dim page = doc.NewPage()

        Dim rc = Util.AddNote(
            "在此示例中,“提交”按钮与 ActionSubmitForm 操作关联," +
            "",
            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 = 72.0F * 2 + 46
        Dim fldHeight = tf.FontSize * 1.2F
        Dim dY = 32.0F

        '' 文本区域:
        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

        '' 文本区域:
        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

        '' 复选框:
        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

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

        '' 提交表单按钮:
        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

        '' 提交网址:
        btnSubmit.Widget.Activate = New ActionSubmitForm("/Samples/HandleFormSubmitFields")
        doc.AcroForm.Fields.Add(btnSubmit)

        '' 重置表单按钮:
        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.Activate = New ActionResetForm()
        btnReset.Widget.Page = page
        doc.AcroForm.Fields.Add(btnReset)
        ip.Y += dY
        ''
        '' 完毕:
        doc.Save(stream)
        Return doc.Pages.Count
    End Function
End Class