This module uses the DevExpress PDF Document API (PdfDocumentProcessor) to process a predefined sample file.
Select the operation from the drop-down button: delete form fields or convert them to static content. You can Process All Fields or clear this option and select specific fields in the Custom Field List editor.
Click Remove Form Fields and Save or Flatten Form Fields and Save to process the sample document and download the result.
using DevExpress.Pdf;
Stream FlattenForm(MemoryStream documentStream, bool flattenAll, string[] fieldsToFlatten) {
using var processor = new PdfDocumentProcessor();
processor.LoadDocument(documentStream);
if (flattenAll)
processor.FlattenForm();
else
foreach (var field in fieldsToFlatten)
processor.FlattenFormField(field);
var outputStream = new MemoryStream();
processor.SaveDocument(outputStream);
outputStream.Position = 0;
return outputStream;
}
Stream RemoveForm(MemoryStream documentStream, bool removeAll, string[] fieldsToRemove) {
using var processor = new PdfDocumentProcessor();
processor.LoadDocument(documentStream);
if(removeAll)
processor.RemoveForm();
else
foreach(var field in fieldsToRemove)
processor.RemoveFormField(field);
var outputStream = new MemoryStream();
processor.SaveDocument(outputStream);
outputStream.Position = 0;
return outputStream;
}