In the realm of software development, working with Portable Document Format (PDF) files is often inevitable. Whether you're creating, manipulating, or converting PDFs, having a reliable library can significantly streamline your workflow. For .NET developers, the iTextSharp library, now known as iText7 for .NET, stands out as a robust and feature-rich PDF library. This article delves into the world of PDF libraries in C#, focusing on iText7 for .NET.

iText7 for .NET is an open-source PDF creation, manipulation, and extraction library that supports .NET Framework, .NET Core, and .NET 5. It offers a wide range of features, including creating and modifying PDFs, adding annotations, and extracting text and metadata. With its extensive documentation and active community, iText7 for .NET is a popular choice among C# developers.

Getting Started with iText7 for .NET
Before diving into the features, let's first discuss how to get started with iText7 for .NET. The library is available via NuGet, making it easy to integrate into your existing projects.

To install iText7 for .NET, open the Package Manager Console in Visual Studio and run the following command:
Install-Package iText7
Once installed, you can start using iText7 in your C# code. Here's a simple example of creating a new PDF:

using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
PdfWriter writer = new PdfWriter("output.pdf");
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf);
document.add(new Paragraph("Hello, iText7!"));
pdf.close();
Creating PDFs from Scratch
iText7 for .NET allows you to create PDFs from scratch with ease. You can add various elements like paragraphs, images, tables, and more to your PDFs. Here's an example of creating a PDF with a table:
using iText.Layout.Element;
Table table = new Table(2);
table.addCell("Hello");
table.addCell("World!");
document.add(table);
iText7 also supports adding lists to your PDFs. You can create ordered or unordered lists, and even nested lists. Here's an example of an unordered list:

using iText.Layout.Element;
List unorderedList = new List().setSymbolIndent(12).setListSymbol("-");
unorderedList.add("Item 1");
unorderedList.add("Item 2");
document.add(unorderedList);
Manipulating Existing PDFs
iText7 for .NET isn't limited to creating new PDFs; it also allows you to manipulate existing PDFs. You can add, remove, or modify content, add annotations, and more. Here's an example of adding a new page to an existing PDF:
PdfDocument pdfDoc = new PdfDocument(new PdfReader("input.pdf"), new PdfWriter("output.pdf"));
Document document = new Document(pdfDoc);
document.add(new Paragraph("This is a new page!"));
pdfDoc.close();
iText7 also supports extracting text and metadata from PDFs. This can be useful for various applications, such as text extraction for search engines or metadata manipulation for compliance purposes.

Advanced Features of iText7 for .NET
iText7 for .NET offers a wide range of advanced features to cater to more complex PDF manipulation needs. Some of these features include:




















Working with Annotations
iText7 allows you to add, modify, and extract annotations from PDFs. Annotations can be used to add notes, highlight text, or draw shapes on a PDF. Here's an example of adding a note annotation:
using iText.Kernel.Pdf.Annotations; NoteAnnotation note = new NoteAnnotation(100, 100, 200, 200, "This is a note!"); pdfDoc.addAnnotation(note);
Working with Form Fields
iText7 supports working with PDF form fields. You can create, modify, or extract form fields, which can be useful for creating interactive PDF forms. Here's an example of creating a text field:
using iText.Kernel.Pdf.Forms; TextFormField textField = new TextFormField(new Rectangle(100, 100, 200, 200), "Text Field"); pdfDoc.addFormField(textField);
iText7 for .NET is a powerful library that offers a wide range of features for working with PDFs in C#. Whether you're creating, manipulating, or extracting PDFs, iText7 for .NET provides a robust and feature-rich solution. With its extensive documentation and active community, it's a great choice for any .NET developer working with PDFs.
So, why wait? Start exploring iText7 for .NET today and unlock the full potential of PDF manipulation in your C# projects. Happy coding!