Using the CheckBox and RadioButton components.
Example_26.pdf — the PDF this example creates.
/*
* Example_26.java
*
* Copyright (c) 2026 PDFjet Software
* Licensed under the MIT License. See LICENSE file in the project root.
*/
package examples;
import java.io.*;
import com.pdfjet.*;
import com.pdfjet.fonts.*;
/**
* Example_26.java
*/
public class Example_26 {
public Example_26() throws Exception {
PDF pdf = new PDF(
new BufferedOutputStream(new FileOutputStream("Example_26.pdf")));
Font f1 = new Font(pdf, IBMPlexSans.Bold);
f1.setSize(10f);
Page page = new Page(pdf, Letter.PORTRAIT);
float x = 50f;
float y = 50f;
new CheckBox(f1, "Hello")
.setLocation(x, y)
.setCheckmarkColor(Color.blue)
.check(Mark.CHECK)
.drawOn(page);
y += 30f;
new CheckBox(f1, "World!")
.setLocation(x, y)
.setCheckmarkColor(Color.blue)
.setURIAction("http://pdfjet.com")
.check(Mark.CHECK)
.drawOn(page);
y += 30f;
new CheckBox(f1, "This is a test.")
.setLocation(x, y)
.setURIAction("http://pdfjet.com")
.drawOn(page);
y += 30f;
new RadioButton(f1, "Hello, World!")
.setLocation(x, y)
.select(true)
.drawOn(page);
float[] xy = (new RadioButton(f1, "Yes"))
.setLocation(x + 100f, 50f)
.setURIAction("http://pdfjet.com")
.select(true)
.drawOn(page);
xy = (new RadioButton(f1, "No"))
.setLocation(xy[0], 50f)
.drawOn(page);
xy = (new CheckBox(f1, "Hello"))
.setLocation(xy[0], 50f)
.setCheckmarkColor(Color.blue)
.check(Mark.X)
.drawOn(page);
xy = (new CheckBox(f1, "Yahoo")
.setLocation(xy[0], 50f)
.setCheckmarkColor(Color.blue)
.check(Mark.CHECK)
.drawOn(page));
Rect rect = new Rect(xy[0], xy[1], 20f, 20f);
rect.setBorderColor(Color.black);
rect.drawOn(page);
pdf.complete();
}
public static void main(String[] args) throws Exception {
long time0 = System.currentTimeMillis();
new Example_26();
long time1 = System.currentTimeMillis();
System.out.printf("Example_26 => %4d ms%n", time1 - time0);
}
} // End of Example_26.java
©2026 PDFjet Software.