Example_45

Another example of using the Form and Field components.

Example_45.pdf — the PDF this example creates.

/*
 * Example_45.cs
 *
 * Copyright (c) 2026 PDFjet Software
 * Licensed under the MIT License. See LICENSE file in the project root.
 */
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;

using PDFjet.NET;

/**
 * Example_45.cs
 */
public class Example_45 {
    public Example_45() {
        PDF pdf = new PDF(new BufferedStream(
                new FileStream("Example_45.pdf", FileMode.Create)));

        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 List<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) {
        Stopwatch sw = Stopwatch.StartNew();
        long time0 = sw.ElapsedMilliseconds;
        new Example_45();
        long time1 = sw.ElapsedMilliseconds;
        sw.Stop();
        Console.WriteLine($"Example_45 => {time1 - time0,4} ms");
    }
}   // End of Example_45.cs

©2026 PDFjet Software.