IRONSOFTWAREHOME

How to Flatten PDFs in IronPDF C#

Curtis Chau
Curtis Chau
Updated: August 2, 2026

IronPDF flattens PDF documents in C# with the Flatten() method, converting interactive form fields into static content so the document can no longer be modified.

PDF documents often include interactive forms with fillable widgets such as radio buttons, checkboxes, text boxes, and lists. To make these documents non-editable for security or archival purposes, you flatten the PDF file. This applies when working with PDF forms in business applications, legal documents, or any scenario requiring a permanent record.

Quickstart: Flatten Your PDF in a Few Lines

Flatten PDF documents using IronPDF to remove all interactivity and create permanent, non-editable content. This C# snippet loads an existing PDF, removes all fillable widgets, and saves the secured document.

  1. 1Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. 2Copy and run this code snippet.

    var pdf = IronPdf.PdfDocument.FromFile("input.pdf");
    pdf.Flatten();
    pdf.SaveAs("flattened.pdf");
    C#
  3. 3Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer

How Do I Flatten a PDF Document in C#?

Once IronPDF is installed, you can flatten PDF files with a single method call. The process works on existing PDF documents and on PDFs you render from HTML files before flattening.

The code example below uses the PdfDocument class to load an existing PDF. For dynamic PDF generation, render the form with the ChromePdfRenderer class before flattening.

To flatten a PDF file, call the Flatten method. This removes all interactive widgets including radio buttons, checkboxes, and text fields, making the document non-editable.

Input

using IronPdf;

// Select the desired PDF File
PdfDocument pdf = PdfDocument.FromFile("before.pdf");

// Flatten the pdf
pdf.Flatten();

// Save as a new file
pdf.SaveAs("after_flatten.pdf");

Output

For complex scenarios, flatten specific pages or set form data before flattening. Pass a list of zero-based page indexes to flatten only those pages:

using IronPdf;

// Load a PDF with fillable forms
PdfDocument pdf = PdfDocument.FromFile("form-document.pdf");

// Optionally, pre-fill form fields by name before flattening
pdf.Form.FindFormField("name").Value = "John Doe";
pdf.Form.FindFormField("email").Value = "john@example.com";

// Flatten only pages 1-3, passing their zero-based indexes
pdf.Flatten(new[] { 0, 1, 2 });

// Save the result
pdf.SaveAs("flattened-form.pdf");
C#

My favorite library of this kind is IronPDF. It allows for fast and efficient manipulation of PDF files. It also has many valuable features, like exporting to PDF/A format and digitally signing PDF documents.

Milan Jovanovic

Microsoft MVP

View case study

IronOCR means we can save $40,000 annually from manual processing, while enhancing productivity and freeing up resources for high-impact tasks. I would highly recommend it.

Brent Matzelle

Chief Technology Officer, OPYN

View case study

How Can I Verify the PDF Is Flattened?

The output below shows the before and after states. The first PDF contains editable form fields. After the flatten method runs, the document becomes non-editable. This code works in any .NET project, including Blazor apps.

Flattened PDF
Please note: Forms will not be detectable after using the Flatten method.

To verify successful flattening, check the form field count:

using IronPdf;

// Load the flattened PDF
PdfDocument flattenedPdf = PdfDocument.FromFile("flattened.pdf");

// FormFieldCollection exposes Count directly on the Form property
if (flattenedPdf.Form.Count == 0)
{
    Console.WriteLine("PDF has been successfully flattened - no interactive fields remain.");
}
else
{
    Console.WriteLine($"Warning: {flattenedPdf.Form.Count} form fields still exist.");
}
C#

What Happens to Form Fields After Flattening?

When you flatten a PDF document, every interactive form element becomes part of the page content. Form fields turn into static text and graphics:

  • Text fields become regular text on the page
  • Checkboxes and radio buttons become static images showing their selected state
  • Dropdown menus display only the selected value as plain text
  • Digital signatures are preserved visually but lose cryptographic validation

This process is irreversible. Keep a copy of the original interactive PDF if you need future editing capabilities. Flattening keeps text and vector content selectable, unlike rasterizing pages to images, which converts each page into a flat picture. For documents requiring both security and editability, use PDF permissions and passwords instead of flattening.

When Should I Flatten My PDF Documents?

Common cases for flattening:

  1. Legal Document Archival: Flatten contracts and agreements after signing to prevent content alteration and maintain legal integrity.
  2. Report Distribution: Flatten financial reports and data sheets with calculated fields before distribution to prevent tampering.
  3. Form Submission Processing: Create permanent records by flattening PDFs after users complete online forms.
  4. Printing Optimization: Flattened PDFs print more reliably since printers don't process interactive elements.
  5. File Size Reduction: Flattening can reduce file size by removing form field data structures, which pairs well with PDF compression.

Here's a batch processing example for archiving multiple completed forms:

using IronPdf;
using System.IO;

public class BatchPdfFlattener
{
    public static void FlattenAllPdfsInDirectory(string sourceDir, string outputDir)
    {
        // Ensure output directory exists
        Directory.CreateDirectory(outputDir);
        
        // Get all PDF files in source directory
        string[] pdfFiles = Directory.GetFiles(sourceDir, "*.pdf");
        
        foreach (string pdfFile in pdfFiles)
        {
            try
            {
                // Load the PDF
                PdfDocument pdf = PdfDocument.FromFile(pdfFile);
                
                // Flatten the document
                pdf.Flatten();
                
                // Save to output directory with "_flattened" suffix
                string fileName = Path.GetFileNameWithoutExtension(pdfFile);
                string outputPath = Path.Combine(outputDir, $"{fileName}_flattened.pdf");
                pdf.SaveAs(outputPath);
                
                Console.WriteLine($"Flattened: {fileName}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error processing {pdfFile}: {ex.Message}");
            }
        }
    }
}

Conclusion

Flattening converts a PDF's interactive form fields into static page content with a single Flatten() call, locking the document against further edits. Keep an unflattened copy if you might need to change the data later, since the operation cannot be undone.

If you need to populate fields first, set the form values before flattening; to assemble locked documents, merge or split them afterward.


Library Quick Access

Documentation

Read More Documentation

Read the Documentation for more on how to flatten PDFs, edit and manipulate them, and more.

Visit IronPDF Documentation

Ready to see what else you can do? Check out our tutorial page here: Additional Features

Frequently Asked Questions

What does it mean to flatten a PDF in C#?

Flattening a PDF with IronPDF involves converting interactive form fields like text boxes, checkboxes, and radio buttons into static content. This prevents further modifications to the document.

How can I flatten a PDF document using IronPDF?

To flatten a PDF document using IronPDF, you need to load the document with `PdfDocument.FromFile()`, call the `Flatten()` method, and then save the flattened version with `SaveAs()`.

Can I flatten specific pages of a PDF rather than the entire document?

Yes, you can flatten specific pages by passing an array of zero-based page indices to the `Flatten()` method in IronPDF.

What happens to form fields in a PDF after flattening?

After flattening a PDF with IronPDF, all form fields become part of the static page content. Text fields turn into selectable text, and graphical elements like checkboxes become static images.

Is it possible to verify if a PDF is successfully flattened?

Yes, you can verify that a PDF is flattened by checking the form field count. After flattening with IronPDF, the form fields should count as zero.

Are there benefits to flattening PDFs in certain scenarios?

Flattening PDFs is beneficial for legal and archival purposes, report distribution to prevent tampering, optimizing printing reliability, and reducing file size by removing interactive elements.

How do I process multiple PDFs for flattening in IronPDF?

For batch processing in IronPDF, use a loop to load each PDF file, apply the `Flatten()` method, and save each document using `SaveAs()` with a unique filename.

Is the flattening process reversible in IronPDF?

No, the flattening process is irreversible. It permanently converts interactive elements into non-editable content, so it's crucial to keep an original unflattened copy if future edits are needed.

Do flattened PDFs still retain selectable text and vector graphics?

Yes, while form fields are converted to static content, IronPDF retains selectable text and vector graphics within the document.

Can interactive elements like digital signatures be preserved upon flattening?

Digital signatures are preserved visually after flattening in IronPDF, but cryptographic validation is lost, meaning they remain visible yet are no longer valid signatures.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 21,228,841Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"

Licenses from $999