Case Study: See how Formable built DOCX redlining with Apryse in two months

Home

All Blogs

Extract PDF Form Fields to JSON in C# and .NET

Published June 07, 2023

Updated November 16, 2026

Read time

5 min

email
linkedIn
twitter
link

Extract PDF Form Fields to JSON in C# and .NET

Sanity Image

John Chow

Product Manager

To extract structured data from a PDF in C# with the Apryse Server SDK, you install the SDK, add the Data Extraction module, initialize with your license key, and run the extraction you need: tables, document structure, form fields, or key-value pairs. You get JSON back. It runs on .NET on Windows and Linux, x64 only.

Three things catch people out. Smart Data Extraction ships as a separate add-on module, so a base SDK install alone will not run it. PDFNet.Initialize() must run before any extraction call, or the call fails. And form field key-value extraction returns more than positions. Each field comes back with its type, bounding box, and confidence score, plus the words of its key (or its label, for checkboxes and radio buttons) and any text inside the field. That lets you map results into an existing schema instead of parsing text. The complete example below extracts form fields from a PDF form and prints the returned JSON.

Sanity Image

This post covers Apryse Server SDK integration using C# on .NET, on Windows x64 and Linux x64, extracting form fields from PDF forms as JSON. It does not cover macOS, ARM, or 32-bit platforms, which Smart Data Extraction does not support. Tabular data and document structure extraction are covered in the Smart Data Extraction docs, and the document structure output format is defined in the StructureOutputJson specification. For plain text extraction, see Text Extraction. For other languages or platforms, see the Server SDK get-started guide.

Reading Form Values Without Parsing Page Text

Copied to clipboard

A PDF stores characters at coordinates on a page. It does not store which characters are a label and which are the answer. Interactive forms carry field data, but flattened and scanned forms do not, and those are the ones that arrive in intake workflows such as insurance claims, onboarding packets, and loan applications.

Smart Data Extraction reads the page and returns structured JSON. It offers two form engines. Form Field Detection returns each field’s type, bounding box, and confidence score. Form Field Key-Value Extraction adds the words of the key printed next to each field, the label beside each checkbox or radio button, and any text inside the field. Each key and label also carries a score for how likely it belongs to its field. Use detection when you only need field locations, for example to build a fillable form. Use key-value extraction when you need the data.

The distinction from base capabilities matters. The base SDK fills and flattens forms and extracts plain text. It does not identify fields on a flat page or pair labels with values. That work needs the Smart Data Extraction add-on package.

The SDK runs inside your own infrastructure. Documents are processed on your server, and no document data leaves your environment.

Extracting Form Fields to JSON in C#

Copied to clipboard

Before you start, install the latest active .NET SDK, plus Visual Studio on Windows or a code editor on Linux.

Install the base SDK with NuGet. On Windows x64, go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution in Visual Studio, search for PDFTron.NET.x64, select it, and install it. On Linux x64, run dotnet add package PDFTron.NET.x64 in your project folder. macOS and ARM are not supported for extraction. On Linux, both form engines need GLIBC 2.31 or newer.

Then download the Data Extraction module for your platform from the modules page and expand it into a Lib folder next to your built application. Pass that Lib folder, not the Windows or Linux subfolder inside it, to AddResourceSearchPath.

License keys are confidential. Do not commit them to public repositories. Use environment variables or a secrets manager to inject your key at runtime.

The example below goes in the Program.cs of a .NET 8 console project. It initializes the SDK, confirms the module is present, runs the key-value engine, and prints the JSON.

ExtractData takes the input path and an engine, and returns the JSON as a string. Swap in e_form to run the detection engine, which returns type, bounding box, and confidence score only. Replace exam-form.pdf with your own file.

The output follows the JSON specification for form field identification. This excerpt shows two of the elements returned for a two-page exam form: a text field with its key, and a radio button with its label. The full output includes text fields, checkboxes, radio buttons, and combo boxes. In this output, the words arrays on the fields themselves are empty. Text found inside a field appears in that element’s words array.

Keys and labels come back as individual words. Join the content values in order to get the text. Here, Capybara and ID make “Capybara ID”.

Production Considerations

Copied to clipboard
  • Trial output differs from licensed output: In evaluation mode, extraction caps at 100 pages per operation, inserts a random watermark page, and can add an evaluation message to the JSON. Do not build test fixtures from trial output.
  • Check the module once, at startup: IsModuleAvailable returns false when the SDK cannot find the module. Check the resource search path first. Run the check when the process starts, fail fast, and call Initialize once per process rather than per document.
  • Gate on confidence: Every element, key, and label carries a confidence score from 0.0 to 1.0. It reflects how likely the box contains an object and how accurate the box is. Keys and labels also carry a linkingConfidence score, which reflects how likely they relate to their field. Neither score rates the accuracy of the text. Pick thresholds from your own documents and route low scores to a review step. The SDK does not provide that queue, so you build it.
  • Do not assume every field has a key: fieldKey and label are optional, and several fields can share one key. In a two-page test form, a column header was the key for every field beneath it, and a few elements had no key or label.
  • Log runInfo: Each run returns a runInfo object. It reports the producer platform and version, and can carry errors and warnings arrays. Log it with every document, and treat a document with errors as failed.
  • Scanned and protected forms need options: The extraction options cover OCR language, PDF password, page range, and region of interest. Set the OCR language option for scanned forms in other languages, and the password option for protected PDFs. See the workflow guide.
  • Match your build machine to the platform: Extraction runs on x64 Windows and Linux only. A developer on an ARM or macOS machine cannot run it locally. Use an x64 Linux container or machine for local runs.

What to Test

Copied to clipboard
  • Key accuracy: Run 10 real forms. Join the content of each fieldKey’s words and compare the result with the question printed next to the field.
  • Choice labels: For checkboxes and radio buttons, join the content of each label’s words and compare it with the text beside the choice. Check grids where one header serves several rows.
  • Entered text: Fill in a copy of a form and confirm each element’s words array holds what you typed.
  • Box placement: Check properties.coordinateSystem first. In originTop the origin is at the top left, so top is less than bottom. In PDF the origin is at the bottom left. Render the page, draw each rect ([left, top, right, bottom], in PDF points) on it, and confirm each box sits on its field. On rotated pages, coordinates are in the rotated space.
  • Missing and shared keys: Count the elements with no fieldKey or label, and the fields that share one key. Decide how your pipeline handles each.
  • Confidence spread: Log confidence and linkingConfidence across a batch, and inspect the lowest scores by hand. In a two-page test form, the only element below 0.999 was a 0.299 text field that sat on printed text.
  • Field types: Run a form with radio groups and combo boxes, and confirm each element comes back with the type you expect.

Getting Started

Copied to clipboard

Install PDFTron.NET.x64 from NuGet in Visual Studio on Windows x64, or run dotnet add package PDFTron.NET.x64 on Linux x64, as the .NET get-started guide describes. Download the Data Extraction module from the modules page and follow the workflow guide to install it. The form field guide has the working C# samples. Get your free trial key at dev.apryse.com before running the code.