This sample shows how to use buttons in your PDF document.

You can add buttons to your PDF document using PdfPage.AddButton(..) method. This method returns an instance of PdfButton class.

You can also associate actions with buttons using properties in PdfButton class whose names start with "On" (e.g. OnMouseDown).

C#
using System.Diagnostics;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class Buttons
    {
        public static void Main()
        {
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "Buttons.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfPage page = pdf.Pages[0];

                PdfButton button = page.AddButton(10, 50, 100, 50);
                button.BackgroundColor = new PdfGrayColor(60);
                button.BorderColor = new PdfRgbColor(128, 0, 128);
                button.Text = "Button";

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
    }
}
VB
Imports System.Diagnostics
Imports System.IO

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class Buttons
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            ' for more information.

            Dim pathToFile As String = "Buttons.pdf"

            Using pdf As New PdfDocument()
                Dim page As PdfPage = pdf.Pages(0)

                Dim button As PdfButton = page.AddButton(10, 50, 100, 50)
                button.BackgroundColor = New PdfGrayColor(60)
                button.BorderColor = New PdfRgbColor(128, 0, 128)
                button.Text = "Button"

                pdf.Save(pathToFile)
            End Using

            Process.Start(pathToFile)
        End Sub
    End Class
End Namespace