PDF before flattening
Flattening process
PDF after flattening

Get started with IronPDF

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

First Step:
green arrow pointer



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;

// This code demonstrates how to flatten a PDF document using the IronPdf library.
public class PdfProcessor
{
    public static void Main()
    {
        // Load the PDF document from the specified file path.
        // This method creates a PdfDocument object by reading a PDF from the file system.
        PdfDocument pdf = PdfDocument.FromFile("before.pdf");

        // Flattening a PDF merges all the interactive elements with the content layer,
        // making them non-editable. This is useful for preserving the appearance of the document
        // when shared with others who do not require the ability to edit the interactive fields.
        // The following line flattens the PDF.
        pdf.Flatten();

        // Save the flattened PDF document to a new file. This is useful for keeping the original file intact
        // while creating a separate flat version that can be distributed or archived.
        pdf.SaveAs("after_flatten.pdf");
    }
}
Imports IronPdf



' This code demonstrates how to flatten a PDF document using the IronPdf library.

Public Class PdfProcessor

	Public Shared Sub Main()

		' Load the PDF document from the specified file path.

		' This method creates a PdfDocument object by reading a PDF from the file system.

		Dim pdf As PdfDocument = PdfDocument.FromFile("before.pdf")



		' Flattening a PDF merges all the interactive elements with the content layer,

		' making them non-editable. This is useful for preserving the appearance of the document

		' when shared with others who do not require the ability to edit the interactive fields.

		' The following line flattens the PDF.

		pdf.Flatten()



		' Save the flattened PDF document to a new file. This is useful for keeping the original file intact

		' while creating a separate flat version that can be distributed or archived.

		pdf.SaveAs("after_flatten.pdf")

	End Sub

End Class
$vbLabelText   $csharpLabel

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

Documentation

Read More Documentation

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

Visit IronPDF Documentation

Frequently Asked Questions

What is PDF flattening?

PDF flattening is the process of converting interactive PDF elements, such as forms and annotations, into a static format that makes the document uneditable.

Why would you need to make a PDF uneditable in C#?

Flattening a PDF in C# is useful for creating uneditable documents, ensuring the contents cannot be altered, which is beneficial for archiving, compliance, and secure document distribution.

How can a library help in flattening PDFs?

IronPDF provides a straightforward method to flatten PDFs using C# code. You can use its library to convert interactive PDFs into flat, non-editable documents with a single line of code.

What is the basic code to flatten a PDF using a library?

To flatten a PDF using IronPDF, you load the PDF using the PdfDocument class, call the Flatten method, and save the flattened PDF. This process removes all interactive elements from the document.

What are the steps to make a PDF document uneditable in C#?

The steps include installing IronPDF from the NuGet Package Manager, loading an existing or creating a new PDF, using the Flatten method, and saving the flattened PDF as a new document.

Can a library flatten any PDF document?

Yes, IronPDF can flatten any PDF document, making it non-editable by removing interactive elements like forms, checkboxes, and radio buttons.

Do I need any specific software to flatten PDFs?

You need to install the IronPDF software, which can be added to your project via the NuGet Package Manager, to use its functionalities including PDF flattening.

Where can I find more documentation on using a PDF library?

You can read more documentation on IronPDF's official website, which provides comprehensive guides and API references for using the library to manipulate PDFs.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.