Saves the visible appearance of filled form fields so viewers can show their values. shipping.pdf is in the example ZIP.
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) return; int count = form.GenerateMissingAppearances(); doc.Save("visible.pdf"); Console.WriteLine(count);
Unzip the example, then dotnet run.
Writes visible.pdf and prints the number of appearances stored:
3The full program
In the sample, City is Portland but the widget has no stored drawing. The download checks the saved file for the drawings and reads City back without changing its value. If opened without AllowEditing = true, the generation call throws InvalidOperationException.
using System; using System.Linq; using OnePdf; using var doc = PdfDocument.Open("shipping.pdf", new() { AllowEditing = true }); var form = doc.Form ?? throw new InvalidOperationException("No AcroForm."); Console.WriteLine($"Text widgets with a stored drawing before: {CountDrawings(form)}"); int count = form.GenerateMissingAppearances(); doc.Save("visible.pdf"); Console.WriteLine($"Appearances stored: {count}"); using var saved = PdfDocument.Open("visible.pdf"); var savedForm = saved.Form!; Console.WriteLine($"Text widgets with a stored drawing after: {CountDrawings(savedForm)}"); Console.WriteLine($"Viewer asked to draw fields: {savedForm.NeedAppearances}"); Console.WriteLine($"City is still: {savedForm.FindField("shipping.city")!.Value}"); static int CountDrawings(PdfAcroForm form) => form.TerminalFields .Where(field => field.Kind == PdfFieldKind.Text) .SelectMany(field => field.Widgets) .Count(widget => widget.GetDictionary("AP")?.Get("N") is PdfStream);
Text widgets with a stored drawing before: 0 Appearances stored: 3 Text widgets with a stored drawing after: 3 Viewer asked to draw fields: False City is still: Portland
Variations
Check whether the saved form still asks the viewer to draw fields. After running the snippet at the top, add these lines:
using var saved = PdfDocument.Open("visible.pdf"); Console.WriteLine(saved.Form!.NeedAppearances);
FalseThis reads the flag from the file you just wrote. It isn’t a general test that every field looks right.
Related recipes
The short answer
Open the PDF with AllowEditing = true, call doc.Form.GenerateMissingAppearances(), and save to a new file. This stores the drawings for existing AcroForm fields without replacing their values or baking the fields into the page. If there’s no AcroForm, this isn’t a way to add fillable boxes to a scanned or static PDF.
Why is my fillable PDF form not displaying field data?
A PDF form stores the answer and the drawing separately. The field value (/V) can contain Portland while the widget (the control that appears on the page) has no normal appearance stream (/AP /N). A viewer that doesn’t generate a replacement can show an empty box even though code can read the value. If the value itself is empty, generating an appearance won’t restore it; fill the field first. OnePDF’s regular fill methods already generate appearances unless you turn that off.
Some forms set /NeedAppearances to ask the viewer to build the drawings. In that case OnePDF rebuilds text and choice appearances even if they already have a stream, because it may be stale. The forms docs say the flag “is cleared only when every widget has a normal appearance (a button that is off needs none).” The number returned by the call is the number of appearances stored, not a count of values changed.
Why do fillable fields disappear after I save a PDF?
If the fields are still in the saved form but look empty, check the stored value and the appearance separately. If the fields are gone from the form itself, a save workflow that flattened them is a different case: flattening paints the widgets onto the page and removes the interactive fields. Skip flattening if people need to keep filling the PDF. GenerateMissingAppearances() saves the drawings with the widgets, so the widgets remain in the form.
Open the result in the viewer you’ll use to distribute it. The appearance documentation explains that the generator uses simple fonts, drops characters it can’t encode and doesn’t shape right-to-left text. A stored drawing can therefore differ from the field’s text even though the underlying value is unchanged.