Form fields are not removing from PDF

I have written the code below to delete the form fields from an existing PDF that I am trying to update. When the process is finished and I review the pdf using Adobe Acrobat, all the form fields are displayed rather than a clean pdf.

var folderPath = Path.Combine(_environment.ContentRootPath, "Files");
var files = Directory.GetFiles(folderPath);
foreach(var file in files)
{

FileStream fileStream = new FileStream(file, FileMode.Open, FileAccess.Read);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream);
PdfLoadedForm loadedForm = loadedDocument.Form;
var fieldsCount = loadedDocument.Form.Fields.Count;
var pages = loadedDocument.Pages;
for(int i = fieldsCount-1; i >= 0; i--)
{
loadedForm.Fields.RemoveAt(i);
}
MemoryStream stream = new MemoryStream();
loadedDocument.Save(stream);
loadedDocument.Close(true);
}


1 Reply

IJ Irfana Jaffer Sadhik Syncfusion Team July 11, 2023 06:08 AM UTC

We have checked the reported behavior with the test PDF document on our end and the form fields are properly removed from the PDF document. We have attached the sample and the video for your reference. Please check this on your end and let us know the result.


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/NetCoreSample1362496673 Video: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ScreenCapture_7-11-2023_11.21.34_AM.mp4876130885


We suspect that the issue might be with the specific PDF document. We request you to share the modified sample with us. So that we can assist you further in this. 


Loader.
Up arrow icon