Flatten PDFs in C#

PDF documents often include forms featuring interactive fillable widgets, such as radio buttons, checkboxes, text boxes, lists, etc. In order to make it non-editable for different application purposes, we need to flatten the PDF file. IronPDF provides the function to flatten your PDF in C# with just one line of code.


C# NuGet Library for PDF

Install with NuGet

Install-Package IronPdf
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

C# NuGet Library for PDF

Install with NuGet

Install-Package IronPdf
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer

Check out IronPDF on Nuget for quick installation and deployment. With over 8 million downloads, it's transforming PDF with C#.

C# NuGet Library for PDF nuget.org/packages/IronPdf/
Install-Package IronPdf

Consider installing the IronPDF DLL directly. Download and manually install it for your project or GAC form: IronPdf.zip

Manually install into your project

Download DLL

Flatten C# PDF Document

Once the IronPDF package is installed, you can flatten your PDF file with just one line of code.

In the code example below, we have selected our PDF using the PdfDocument class. If your project requires it, you can also create a PDF using the ChromePdfRenderer class.

To flatten a PDF file, use the Flatten method. This will make the PDF uneditable, removing interactive widgets like radio buttons and checkboxes. Let's see it in action in the flatten PDF C# code example below.

:path=/static-assets/pdf/content-code-examples/how-to/pdf-image-flatten-csharp-flatten-pdf.cs
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");
Imports IronPdf

' Select the desired PDF File
Private pdf As PdfDocument = PdfDocument.FromFile("before.pdf")

' Flatten the pdf
pdf.Flatten()

' Save as a new file
pdf.SaveAs("after_flatten.pdf")
VB   C#

Check the Flattened Document

In the below output, the first PDF is editable, our original file. Using IronPDF and the code above, we have made it flat or non-editable. You can use this code for any of your .NET PDF project needs.

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


Library Quick Access

Read More Documentation

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

Read More Documentation