How to Create Fillable PDF Forms

This sample shows how to use buttons, editboxes, checkboxes, comboboxes in your PDF document.

C# :

using PDFMosaic;
using System;

namespace PDFForm
{
  class PDFForm
  {
    static void Main(string[] args)
    {
      PDFDocument doc = new PDFDocument();
      PDFPage page = new PDFPage(PDFPaperFormat.A4);

      PDFPushButton button = new PDFPushButton(10, 40, 100, 30, "btn1");
      button.Caption = "Button";
      page.Annotations.Add(button);

      PDFCheckBox checkBox = new PDFCheckBox(10, 100, 20, 20, "checkBox");
      checkBox.Checked = true;
      page.Annotations.Add(checkBox);

      PDFComboBox comboBox = new PDFComboBox(10, 200, 100, 20, "comboBox");
      comboBox.BackgroundColor = new PDFColorRGB(0, 255, 0);
      comboBox.Font.Size = 8;
      comboBox.Editable = true;
      comboBox.Text = "Editable combo box";
      comboBox.Items.Add("First item");
      comboBox.Items.Add("Second item");
      page.Annotations.Add(comboBox);

      PDFEditBox edit = new PDFEditBox(20, 300, 100, 50, "edit");
      edit.Multiline = true;
      edit.Font.Size = 8;
      edit.Text = "The quick brown fox jumps over, the lazy dog.";
      page.Annotations.Add(edit);

      doc.Pages.Add(page);

      doc.Save("PDFForms.pdf", true);
    }
  }
}

 

Visual Basic :


Imports PDFMosaic
Imports System

Module PDFForms
  Sub Main()
    Dim document As New PDFDocument()
    Dim page As New PDFPage(PDFPaperFormat.A4)

    Dim button As New PDFPushButton(10, 40, 100, 30, "btn")
    button.Caption = "Button"
    page.Annotations.Add(button)

    Dim checkBox As New PDFCheckBox(10, 100, 20, 20, "checkBox")
    checkBox.Checked = True
    page.Annotations.Add(checkBox)

    Dim comboBox As New PDFComboBox(10, 200, 100, 20, "comboBox")
    comboBox.BackgroundColor = New PDFColorRGB(0, 255, 0)
    comboBox.Font.Size = 8
    comboBox.Editable = True
    comboBox.Text = "Editable combo box"
    comboBox.Items.Add("First item")
    comboBox.Items.Add("Second item")
    page.Annotations.Add(comboBox)

    Dim edit As New PDFEditBox(20, 100, 300, 50, "edit")
    edit.Multiline = True
    edit.Font.Size = 8
    edit.Text = "The quick brown fox jumps over, the lazy dog."
    page.Annotations.Add(edit)

    document.Pages.Add(page)

    document.Save("PDFForms.pdf", True)
  End Sub
End Module