Example_45

Another example of using the Form and Field components.

Example_45.pdf — the PDF this example creates.

/*
 * Example_45.java
 *
 * Copyright (c) 2026 PDFjet Software
 * Licensed under the MIT License. See LICENSE file in the project root.
 */
package examples;

import java.io.*;
import java.util.*;
import com.pdfjet.*;
import com.pdfjet.fonts.*;

/**
 * Example_45.java
 */
public class Example_45 {
    public Example_45() throws Exception {

        PDF pdf = new PDF(
                new BufferedOutputStream(
                        new FileOutputStream("Example_45.pdf")));

        Font f1 = new Font(pdf, IBMPlexSans.Bold);
        Font f2 = new Font(pdf, IBMPlexSans.Regular);

        Page page = new Page(pdf, Letter.PORTRAIT);

        float w = 500f;

        List<Field> fields = new ArrayList<Field>();
        fields.add(new Field(   0f, "Company", "Smart Widgets Construction Inc."));
        fields.add(new Field(   0f, "Street Number", "120"));
        fields.add(new Field(  w/8, "Street Name", "Oak"));
        fields.add(new Field(5*w/8, "Street Type", "Street"));
        fields.add(new Field(6*w/8, "Direction", "West"));
        fields.add(new Field(7*w/8, "Suite/Floor/Apt.", "8W"));
        fields.add(new Field(   0f, "City/Town", "Toronto"));
        fields.add(new Field(  w/2, "Province", "Ontario"));
        fields.add(new Field(7*w/8, "Postal Code", "M5M 2N2"));
        fields.add(new Field(   0f, "Telephone Number", "(416) 331-2245"));
        fields.add(new Field(  w/4, "Fax (if applicable)", "(416) 124-9879"));
        fields.add(new Field(  w/2, "Email", "jsmith12345@gmail.ca"));
        fields.add(new Field(   0f, "Other Information", "Hello, World!"));
        fields.add(new Field(   0f, "", "This is a test."));

        new Form(fields)
                .setLabelFont(f1)
                .setLabelFontSize(8f)
                .setValueFont(f2)
                .setValueFontSize(10f)
                .setLocation(50f, 50f)
                .setWidth(w)
                .drawOn(page);

        pdf.complete();
    }

    public static void main(String[] args) throws Exception {
        long time0 = System.currentTimeMillis();
        new Example_45();
        long time1 = System.currentTimeMillis();
        System.out.printf("Example_45 => %4d ms%n", time1 - time0);
    }
}   // End of Example_45.java

©2026 PDFjet Software.