.NET (1322)
Children categories
This article demonstrates how to remove a particular form field and all of the form fields from an existing PDF document using Spire.PDF.
The below sample document contains some text and five different kinds of form fields:

Remove a particular form field
We can remove a particular form field by calling the PdfFieldCollection.Remove method. To remove the form field by index, call the PdfFieldCollection.RemoveAt method and pass the corresponding index of the form field as the argument.
using Spire.Pdf;
using Spire.Pdf.Fields;
using Spire.Pdf.Widget;
namespace RemoveSpecifiedFormfield
{
class Program
{
static void Main(string[] args)
{
//Create PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Load PDF file
pdf.LoadFromFile(@"Input.pdf");
//Get form fields
PdfFormWidget formWidget = pdf.Form as PdfFormWidget;
//Get and remove the first form field
PdfField textbox = formWidget.FieldsWidget.List[0] as PdfTextBoxFieldWidget;
formWidget.FieldsWidget.Remove(textbox);
//Get and remove the first form field using its name
//PdfField field = formWidget.FieldsWidget["Text1"];
//formWidget.FieldsWidget.Remove(field);
//Remove the form field at index 0
//formWidget.FieldsWidget.RemoveAt(0);
pdf.SaveToFile("DeleteParticularField.pdf");
}
}
}

Remove all of the form fields
To remove all of the form fields, first we need to traverse the form fields and then remove them one by one.
using Spire.Pdf;
using Spire.Pdf.Fields;
using Spire.Pdf.Widget;
namespace RemoveSpecifiedFormfield
{
class Program
{
static void Main(string[] args)
{
//Create PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Load PDF file
pdf.LoadFromFile(@"Input.pdf");
//Get form fields
PdfFormWidget formWidget = pdf.Form as PdfFormWidget;
//Remove all of the form fields
for (int i = formWidget.FieldsWidget.List.Count - 1; i >= 0; i--)
{
PdfField field = formWidget.FieldsWidget.List[i] as PdfField;
formWidget.FieldsWidget.Remove(field);
}
pdf.SaveToFile("DeleteAllFields.pdf");
}
}
}

In the previous article, we have introduced how to read a PST file and get the folder information from it. This article will show you how we can add existing mail message files into PSF file for archiving.
Step 1: Load a PST file from disk into an instance of OutlookFile class.
OutlookFile outlookFile = new OutlookFile(@"C:\Users\Administrator\Documents\Outlook Files\Sample.pst");
Step 2: Load a MSG file into an instance of OutlookItme class.
OutlookItem item = new OutlookItem(); item.LoadFromFile(@"C:\Users\Administrator\Documents\Outlook Files\Sample.msg");
Step 3: Get inbox folder from PST file.
OutlookFolder inboxFolder = outlookFile.RootOutlookFolder.GetSubFolder("Inbox");
Step 4: Add the MSG file to inbox folder.
inboxFolder.AddItem(item);
Full Code:
using Spire.Email;
using Spire.Email.Outlook;
using System;
namespace AddMessageToPSTFile
{
class Program
{
static void Main(string[] args)
{
OutlookFile outlookFile = new OutlookFile(@"C:\Users\Administrator\Documents\Outlook Files\Sample.pst");
OutlookItem item = new OutlookItem();
item.LoadFromFile(@"C:\Users\Administrator\Documents\Outlook Files\Sample.msg");
OutlookFolder inboxFolder = outlookFile.RootOutlookFolder.GetSubFolder("Inbox");
inboxFolder.AddItem(item);
Console.WriteLine("Completed");
}
}
}
Imports Spire.Email
Imports Spire.Email.Outlook
Namespace AddMessageToPSTFile
Class Program
Private Shared Sub Main(args As String())
Dim outlookFile As New OutlookFile("C:\Users\Administrator\Documents\Outlook Files\Sample.pst")
Dim item As New OutlookItem()
item.LoadFromFile("C:\Users\Administrator\Documents\Outlook Files\Sample.msg")
Dim inboxFolder As OutlookFolder = outlookFile.RootOutlookFolder.GetSubFolder("Inbox")
inboxFolder.AddItem(item)
Console.WriteLine("Completed")
End Sub
End Class
End Namespace