How to create checkbox control in PDF document using ByteScout PDF SDK - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

How to create checkbox control in PDF document using ByteScout PDF SDK

  • Home
  • /
  • Articles
  • /
  • How to create checkbox control in PDF document using ByteScout PDF SDK

Adding a text labels wih page numbers to each page of PDF document
Checkbox added into PDF document using Bytescout.PDF lib
The example demonstrates how to create checkboxes using ByteScout PDF SDK.

Program.vb:
VB

'*******************************************************************
'       ByteScout PDF SDK
'                                                                   
'       Copyright © 2016 Bytescout, https://bytescout.com        
'       ALL RIGHTS RESERVED                                         
'                                                                   
'*******************************************************************

Imports Bytescout.PDF

''' <summary>
''' This example demonstrates how to create checkboxes.
''' </summary>
Class Program

    Shared Sub Main()

        ' Create new document
        Dim pdfDocument = New Document()
        pdfDocument.RegistrationName = "demo"
		pdfDocument.RegistrationKey = "demo"
        ' Add page
        Dim page = New Page(PaperFormat.A4)
        pdfDocument.Pages.Add(page)

        ' Add unchecked checkbox
        Dim checkBox1 = New CheckBox(20, 20, 15, 15, "checkBox1")
        page.Annotations.Add(checkBox1)

        ' Add checked checkbox
        Dim checkBox2 = New CheckBox(20, 40, 15, 15, "checkBox2")
        checkBox2.Checked = True
        page.Annotations.Add(checkBox2)

        ' Add readonly checkbox
        Dim checkBox3 = New CheckBox(20, 60, 15, 15, "checkBox3")
        checkBox3.Checked = True
        checkBox3.ReadOnly = True
        page.Annotations.Add(checkBox3)

        ' Draw text labels
        Dim font = New Font(StandardFonts.Times, 12)
        Dim brush = New SolidBrush()
        page.Canvas.DrawString("Unchecked box", font, brush, 45, 20)
        page.Canvas.DrawString("Checked box", font, brush, 45, 40)
        page.Canvas.DrawString("Read-only checked box", font, brush, 45, 60)

        ' Save document to file
        pdfDocument.Save("result.pdf")

        ' Cleanup 
		pdfDocument.Dispose()

        ' Open document in default PDF viewer app
        Process.Start("result.pdf")

    End Sub

End Class 

Program.cs:
C#

//*******************************************************************
//       ByteScout PDF SDK		                                     
//                                                                   
//       Copyright © 2016 ByteScout - https://bytescout.com       
//       ALL RIGHTS RESERVED                                         
//                                                                   
//*******************************************************************

using System.Diagnostics;
using Bytescout.PDF;

namespace CheckBoxes
{
	/// <summary>
	/// This example demonstrates how to create checkboxes.
	/// </summary>
	class Program
	{
		static void Main()
		{
			// Create new document
			Document pdfDocument = new Document();
			pdfDocument.RegistrationName = "demo";
			pdfDocument.RegistrationKey = "demo";
			// Add page
			Page page = new Page(PaperFormat.A4);
			pdfDocument.Pages.Add(page);

			// Add unchecked checkbox
			CheckBox checkBox1 = new CheckBox(20, 20, 15, 15, "checkBox1");
			page.Annotations.Add(checkBox1);
			
			// Add checked checkbox
			CheckBox checkBox2 = new CheckBox(20, 40, 15, 15, "checkBox2");
			checkBox2.Checked = true;
			page.Annotations.Add(checkBox2);
			
			// Add readonly checkbox
			CheckBox checkBox3 = new CheckBox(20, 60, 15, 15, "checkBox3");
			checkBox3.Checked = true;
			checkBox3.ReadOnly = true;
			page.Annotations.Add(checkBox3);
			
			// Draw text labels
			Font font = new Font(StandardFonts.Times, 12);
			Brush brush = new SolidBrush();
			page.Canvas.DrawString("Unchecked box", font, brush, 45, 20);
			page.Canvas.DrawString("Checked box", font, brush, 45, 40);
			page.Canvas.DrawString("Read-only checked box", font, brush, 45, 60);
			
			// Save document to file
			pdfDocument.Save("result.pdf");

			// Cleanup 
			pdfDocument.Dispose();

			// Open document in default PDF viewer app
			Process.Start("result.pdf");
		}
	}
} 

Tutorials:

prev
next