Try it on the included shipping.pdf. It’s an AcroForm, a standard fillable PDF form, not an XFA form or a flat scan.
dotnet add package RecursiveAI.OnePdfRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
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, then dotnet run.
Writes reset.pdf and prints the number of fields reset:
2The 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.
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)"}"); }
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:
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:
var options = new PdfFillOptions { OverrideReadOnly = true }; Console.WriteLine(form.ResetAll(options));
3The saved Order ID is now Unassigned; the field is still marked read-only.
Related recipes
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 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:
form.SetValue("shipping.city", null);The saved City field is empty but its default is still Seattle, so a later reset can restore it.