Flatten PDF API
Flatten PDF forms and annotations into the page content to prevent further editing and ensure document integrity and security.
If you need to flatten a PDF in C#, you’re likely looking for a way to make it read-only, prevent edits, and ensure it looks the same everywhere. Flattening removes interactive elements like form fields and annotations, and can even convert text into vector shapes so it can’t be selected or copied.
In this tutorial, we’ll walk through how to flatten PDF form fields in C#, disable annotations, and protect text using the ConvertAPI PDF Flatten for C#. You’ll get a complete C# PDF flatten example and best practices for preserving quality while securing your documents.

When you flatten PDF form fields in C#, you turn editable inputs into static content, preventing further modifications while keeping their original look.
Flattening annotations such as checkboxes, buttons, and signature fields makes them visible but non-interactive, ensuring no one can alter them.
By converting text into vector paths, you protect PDF text from copying or extraction, making the document fully read-only without losing visual quality.
dotnet add package ConvertApiSign up at ConvertAPI and get your API token. You can find your API token by signing into your ConvertAPI Dashboard.
Store it securely as an environment variable:
setx CONVERTAPI_API_TOKEN "your-api-token"using System;
using System.IO;
using System.Threading.Tasks;
using ConvertApiDotNet;
class Program
{
static async Task Main(string[] args)
{
if (args.Length < 2)
{
Console.WriteLine("Usage: dotnet run -- <input.pdf> <output-folder>");
return;
}
var inputPath = args[0];
var outputDir = args[1];
// Get API token from environment variable
var apiToken = Environment.GetEnvironmentVariable("CONVERTAPI_API_TOKEN");
if (string.IsNullOrWhiteSpace(apiToken))
{
Console.WriteLine("Set CONVERTAPI_API_TOKEN environment variable first.");
return;
}
var api = new ConvertApi(apiToken);
try
{
var res = await api.ConvertAsync("pdf", "flatten",
new ConvertApiFileParam("File", inputPath),
new ConvertApiParam("FlattenControls", "true"),
new ConvertApiParam("FlattenWidgets", "true"),
new ConvertApiParam("FlattenText", "true")
);
await res.SaveFilesAsync(outputDir);
Console.WriteLine($"Flattened PDF saved to: {Path.GetFullPath(outputDir)}");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}var res = await new ConvertApi(Environment.GetEnvironmentVariable("CONVERTAPI_API_TOKEN"))
.ConvertAsync("pdf", "flatten",
new ConvertApiFileParam("File", "input.pdf"),
new ConvertApiParam("FlattenControls", "true"),
new ConvertApiParam("FlattenWidgets", "true"),
new ConvertApiParam("FlattenText", "true")
);
await res.SaveFilesAsync("output-folder");FlattenText set to false if required.With ConvertAPI, PDF flattening in C# is simple, reliable, and high-quality. You can lock form fields, flatten annotations, and protect text with just a few lines of code. Whether you’re building a secure document workflow or need to make a PDF read-only in C#, this solution gives you control without compromising visual fidelity.
Try ConvertAPI PDF Flatten for C# and start flattening PDFs in your next C# project today! Get NuGet package from https://www.nuget.org/packages/ConvertApi