Skip to Content
NexPDF

Forms

List and fill PDF form fields from code in a .NET MAUI app, then refresh the PdfView.

English

License module

Every form call needs the forms module (Indie tier and above).

This page covers AcroForm fields. For XFA forms (XML Forms Architecture), see XFA forms. To fill a PDF from JSON data with placeholders, see Templates.

PdfView shows form fields but has no input UI for them (1.1 included). Build your own MAUI form from the field list and write the values back with FillFormField:

using System.Text.Json.Nodes;
using Nexdevit.NexPdf;

var doc = view.Document!;
foreach (var f in JsonNode.Parse(doc.FormFieldsJson())!.AsArray())
{
    if (f!["kind"]!.GetValue<string>() != "text" || f["read_only"]!.GetValue<bool>()) continue;
    var name = f["name"]!.GetValue<string>();
    var entry = new Entry { Placeholder = name, Text = f["value"]?.ToString() };
    entry.Completed += async (_, _) =>
    {
        try { doc.FillFormField(name, entry.Text ?? ""); }
        catch (NexPdfException e) { System.Diagnostics.Debug.WriteLine(e.Message); }   // a validate script rejected it
        await view.ReloadAsync();
    };
    FieldsLayout.Children.Add(entry);
}

FillFormField runs the field's keystroke and validate scripts and recomputes calculated fields, as a desktop viewer would. Check boxes take "true" or "false"; list fields take the option text.

Field appearances shape text with OpenType and order it with Unicode bidi in embedded fonts, so Arabic, Hebrew, Indic and CJK values display correctly (register a font with NexPdfSdk.RegisterFallbackFont(data) for scripts the bundled fonts do not cover). Right-to-left text without an explicit alignment starts at the right.

Fill from JSON and save

doc.ImportFormJson("""{"applicant.name":"Ana Silva","quantity":"4"}""");
await view.ReloadAsync();
doc.Save(Path.Combine(FileSystem.AppDataDirectory, "filled.pdf"));

Creating fields, FDF and XFDF, recalculation and flattening are in the .NET forms guide.

Put a signature picture in a signature field

A drawn, typed or scanned signature can be shown in a signature field without signing the document digitally, as when a person signs a form on screen. SetSignatureAppearance(name, rgba, width, height) takes the picture as RGBA pixels (width × height × 4 bytes; transparent pixels stay transparent), scales it to fit every widget of the field and centres it. The field must be a signature field that is not read-only. A later digital signature into the same field replaces the picture. The field list then reports has_appearance: true for the field.

// rgba: width * height * 4 bytes, for example from SkiaSharp's SKBitmap.Bytes (Rgba8888).
doc.SetSignatureAppearance("signature", rgba, (uint)width, (uint)height);

The field list also describes how each field is drawn, so a custom UI can lay its own controls over the page: align (left, center or right), font_size (null when the size is automatic), text_color (#rrggbb); text fields add multiline, password, comb, scroll and max_len; signature fields add signed (signed digitally) and has_appearance.

On this page