PDFRasterizer.NET 4.0 is now available. Supports .NET Core. Renders pixel-perfectly.
- How to use a system font for rendering text
- Customize the GUI interaction of a radio button
- Customize the UI interaction of a check box
- How to reduce PDF file size
- How do I create graphics with Icc based colors
- Draw interactively on a PDF page
- Verify a custom digital PDF signature
- How do I use PDFControls.NET in a WPF application
- Fill PDF form
- Flatten PDF form
- Digitally sign a PDF form in C# or VB.NET
- C# render pdf in browser using MVC
- Add hyperlink to PDF
- Rotate a PDF page
- Change the formatting of a numeric field
- Override MouseWheel event
- How to create a thumbnail viewer
- EMF to PDF as vector image
- EMF to PDF as raster image
- Add a rubber stamp annotation with a custom icon
- Create a text annotation in PDF with rich text
- Read and write meta data from PDF
- Use multiple licenses
Flatten PDF form
This code sample shows how to fill out a form and then flatten it. Flattening means that the fields are taken out and the field values are added as static graphics. After flattening, the user can no longer interact with the form fields.
// open 'U.S. Individual Income Tax Return' form
using (FileStream fileIn = new FileStream("f1040a.pdf", FileMode.Open, FileAccess.Read))
{
Document form = new Document(fileIn);
// activate the javascript engine, so format actions will be executed.
form.ScriptBehavior = ScriptBehavior.Format;
// flatten all form-data with the current value, except text-field field-name.
foreach(Field field in form.Fields)
{
TextField textField = field as TextField;
if (textField != null)
{
textField.Value = textField.FullName;
}
foreach( Widget widget in field.Widgets )
{
widget.Persistency = WidgetPersistency.Flatten;
}
}
// write flattened form back to disk
using (FileStream fileOut = new FileStream("flattenform.pdf", FileMode.Create, FileAccess.Write))
{
form.Write(fileOut);
}
}
// open 'U.S. Individual Income Tax Return' form
Using fileIn As New FileStream("..\..\..\inputDocuments\f1040a.pdf", FileMode.Open, FileAccess.Read)
Dim form As New Document(fileIn)
'Activate the javascript engine, so format actions will be executed.
form.ScriptBehavior = ScriptBehavior.Format
'Flatten all form-data with the current value, except text-field field-name.
For Each field As Field In form.Fields
Dim textField As TextField = TryCast(field, TextField)
If textField IsNot Nothing Then
textField.Value = textField.FullName
End If
For Each widget As Widget In field.Widgets
widget.Persistency = WidgetPersistency.Flatten
Next
Next
' write flattened form back to disk
Using fileOut As New FileStream("..\..\flattenform.pdf", FileMode.Create, FileAccess.Write)
form.Write(fileOut)
End Using
End Using
The original PDF form:
The flattened PDF form:

Download PDFControls.NET 2.0
We will send you a download link
Why do we ask your email address?
We send tips that speed up your evaluation
We let you know about bug fixes
You can always unsubscribe with one click
We never share your address with a 3rd party
Thank you for your download
We have sent an email with a download link.