iTextSharp is a popular library for working with PDF files. The unofficial port of the v4.16 is available for .NET core. In this post, I show examples of using the library to programmatically read and fill out a PDF form.
The sample PDF form
For this post, I am using a simple PDF form consisting of the following fields: “First Name”, “Last Name”, and a checkbox. By the way, if you haven’t created a PDF form before, one way to create a form is to use Microsoft Word to design the layout, save the file as a PDF and use Adobe Reader Pro to detect/add the fields.
Get the Library
In your .NET core or ASP.NET core application, add the iiTextSharp.LGPLv2.Core nuget package.
Per the documentation,
iTextSharp.LGPLv2.Core is an unofficial port of the latest LGPL version of the iTextSharp (V4.1.6) to .NET Core.
Get the fields in a PDF form using iTextSharp.
It is straightforward to get the fields using iTextSharp.
public ICollection GetFormFields(Stream pdfStream)
{
PdfReader reader = null;
try
{
PdfReader pdfReader = new PdfReader(pdfStream);
AcroFields acroFields =…