---
title: "Reset PDF form fields to their defaults in C#"
url: https://recursiveai.org/onepdf/cookbook/reset-pdf-form-fields-to-default/
description: "Reset PDF form fields to their saved defaults in C# with OnePDF. Keep the AcroForm fillable and see which fields reset and which stay unchanged."
version: "1.25.1"
---

# Reset PDF form fields to their defaults in C#

**OnePDF** is a free, open-source PDF library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OnePdf) · [GitHub](https://github.com/recursive-ai-oss/onepdf-csharp) · [Docs](https://recursiveai.org/onepdf/docs/) · [Download example (.zip)](https://recursiveai.org/onepdf/cookbook/reset-pdf-form-fields-to-default/reset-pdf-form-fields-to-default.zip)

Try it on the included `shipping.pdf`. It’s an AcroForm, a standard fillable PDF form, not an XFA form or a flat scan.

```shell
dotnet add package RecursiveAI.OnePdf
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using System;
using OnePdf;
using var doc = PdfDocument.Open(
    "shipping.pdf",
    new() { AllowEditing = true });
if (doc.Form is not { } form)
{
    Console.WriteLine("No form in this PDF");
    return;
}
Console.WriteLine(form.ResetAll());
doc.Save("reset.pdf");
```

Unzip [the example](https://recursiveai.org/onepdf/cookbook/reset-pdf-form-fields-to-default/reset-pdf-form-fields-to-default.zip), then `dotnet run`.

Writes `reset.pdf` and prints the number of fields reset:

```text
2
```

## The full program

The download reopens the saved PDF to compare its field values with the input. The sample also has a Delivery note with no default and a read-only Order ID. If you omit `AllowEditing = true`, the reset call throws `InvalidOperationException`.

```csharp
using System;
using System.Linq;
using OnePdf;

using var doc = PdfDocument.Open("shipping.pdf", new() { AllowEditing = true });
if (doc.Form is not { } form)
{
    Console.WriteLine("No form in this PDF");
    return;
}
var before = form.TerminalFields.ToDictionary(field => field.FullName, field => field.Value);
int count = form.ResetAll();
doc.Save("reset.pdf");

Console.WriteLine($"Fields reset: {count}");
using var saved = PdfDocument.Open("reset.pdf");
foreach (var field in saved.Form!.TerminalFields)
{
    string name = field.FullName;
    Console.WriteLine($"{name}: {before[name] ?? "(empty)"} -> {field.Value ?? "(empty)"}");
}
```

```text
Fields reset: 2
shipping.city: Portland -> Seattle
shipping.note: Leave at door -> (empty)
orderId: A-104 -> A-104
```

## Variations

**Reset only City.** In the snippet at the top, replace the line that calls `ResetAll()` with:

```csharp
form.FindField("shipping.city")!.Reset();
```

In the saved copy, City is `Seattle` and Delivery note is still `Leave at door`. If the name comes from a user rather than the sample, check for `null` before calling `Reset()`.

**Include read-only fields.** In the snippet at the top, replace the line that prints the count with:

```csharp
var options = new PdfFillOptions
{
    OverrideReadOnly = true
};
Console.WriteLine(form.ResetAll(options));
```

```text
3
```

The saved Order ID is now `Unassigned`; the field is still marked read-only.

## Related recipes

- [List PDF form field names](https://recursiveai.org/onepdf/cookbook/read-pdf-form-field-names/)
- [Fill a PDF form](https://recursiveai.org/onepdf/cookbook/fill-pdf-form/)
- [Flatten a PDF form](https://recursiveai.org/onepdf/cookbook/flatten-pdf/)

## The short answer

Open an AcroForm PDF with editing allowed, call `doc.Form.ResetAll()`, and save to a new path. `ResetAll()` acts on the fields that hold values, skips read-only fields by default, and doesn’t flatten the form. Use `Reset()` on a single field if you want to keep the other answers.

## How do I reset a fillable PDF form?

A reset changes the answer stored in an existing field; it doesn’t remove the field or recreate its label. The returned count is the number of fields reset, not a count of how many values looked different afterward. Text fields, choice fields, check boxes and radio groups can be reset. Push buttons and signature fields are skipped. A read-only field also stays as it was unless you explicitly override that flag.

For templates you plan to use again, save a separate reset copy and reopen it before handing it off. Compare that copy’s values to the defaults you expect, including any read-only fields. This operation applies to AcroForm fields and doesn’t run the form’s JavaScript, so it won’t recalculate dependent fields for you.

## How do I clear fields in a PDF?

First decide whether “clear” means blank or “back to the template value.” The [forms documentation](https://recursiveai.org/onepdf/docs/forms/#filling) says: “Reset sets `/V` to the inherited `/DV` (or removes it; off for buttons).” Here `/V` is the current value and `/DV` is the default. A default can come from a parent field, so the absence of `/DV` on the field itself doesn’t mean a reset will leave it empty. OnePDF also restores a stored default even if it isn’t among the current choices.

In the sample, resetting Delivery note clears it because it has no default, but City returns to Seattle. To blank a text field regardless of its default, set its current value to `null` instead. Replace the reset call in the snippet at the top with this line:

```csharp
form.SetValue("shipping.city", null);
```

The saved City field is empty but its default is still `Seattle`, so a later reset can restore it.
