ZingPDF logo

Guide

How to flatten a PDF form in C#

Load the PDF, get the form, call FlattenAsync(), and save the result when the output should no longer behave like an interactive form.

Flattening is usually the last step after filling fields. It keeps the visible form content on the page and removes the interactive form structure from the saved document.

The shortest working example

If the PDF contains an AcroForm, flatten it before the final save.

using ZingPDF;

using var pdf = Pdf.Load(File.OpenRead("form.pdf"));

var form = await pdf.GetFormAsync();
if (form is null)
{
    return;
}

await form.FlattenAsync();
await pdf.SaveAsync(File.Create("form-flattened.pdf"));

Flatten when the output should stop behaving like a form

Flattening makes sense when the completed file is going to another system, to a customer, or into an archive and nobody needs to edit the fields any further.

If the next step still needs field values to remain editable, keep the form interactive and save without flattening.

Flatten after you set the field values

The usual sequence is fill first, flatten second, save last.

using ZingPDF;
using ZingPDF.Elements.Forms.FieldTypes.Text;

using var pdf = Pdf.Load(File.OpenRead("form.pdf"));

var form = await pdf.GetFormAsync();
if (form is null)
{
    return;
}

var nameField = await form.GetFieldAsync("Applicant.Name");
if (nameField is not null)
{
    await nameField.SetValueAsync("Taylor Smith");
}

await form.FlattenAsync();
await pdf.SaveAsync(File.Create("form-completed.pdf"));

What flattening changes

ZingPDF writes the current widget appearances onto the page as normal content, removes widget annotations, and removes the form structure from the saved document.

That means the result looks like the completed form, but no longer exposes those fields as editable AcroForm controls.

Need to fill fields before you flatten?

Start with the field lookup and choice-selection path, then flatten as the final step.

Open form-filling guide Open forms docs