USING IRON SUITE

2025 Guide: Best C# PDF Libraries (Free First, Paid When Needed

When most people think about the PDF (Portable Document Format), they think of a file full of information. And they are right, as currently, PDFs are the most commonly used file format for sharing information and have become a standard. But when programmers view the PDFs, they don't see only information; they analyze the format, content type, and other technical aspects of it.

While creating PDF files programmatically, maintaining the structure of the content is the most important task. And it is not as simple a task as it seems because when we say content, it does not mean only text, it includes images, graphs, audio even videos. Also, editing PDFs programmatically is a common requirement now.

In the era of AI, we want to have complete control over the PDFs. Sometimes we need to redact text due to any policy, protect the PDFs to secure the sensitive files, extract data for processing, or dynamically generate reports. There are a lot of use cases for these processes. These are commonly faced problems by developers while processing the PDF files programmatically:

  1. How to maintain a formatted layout for a PDF document while tackling all types of media as content

  2. Extracting text in the correct order, especially if there is text in columns

  3. Memory constraints while processing PDF documents with a lot of pages

  4. Form handling is a major issue faced by developers

  5. Conversion of PDF files to other suitable document types

To ease this task, PDF libraries come in. In this article, we'll discuss multiple C# PDF libraries like IronPDF and Aspose.PDF, and their pricing models. We'll dive into the practical use cases and understand how these libraries make the PDF creation and manipulation programmatically easy and production-ready in a few steps.

1. IronPDF: C# PDF Library

IronPDF is a comprehensive .NET PDF library that developers can use to create, edit PDF documents, convert PDF documents to any other format, and perform many more PDF operations. It uses very minimal memory while processing the large PDF files. It works entirely on your local machine, so you don't depend on the server-level processing to work with it.

This library is compatible with the latest .NET Framework as well, and its integration with the .NET projects is very smooth. You just need to run the following command in NuGet Package Manager, and IronPDF will be ready to use in the project:

Install-Package IronPdf

You don't need to install any other library, as it is fully independent of the external dependencies. When you install this library, it automatically installs all required dependencies at once.

The most important feature of IronPDF is its ability to convert HTML to PDF with pixel-perfect accuracy. IronPDF offers multiple methods to create PDF documents from HTML content. You can convert an HTML string, an HTML file, or a URL directly to PDF. It supports CSS and JavaScript as well to ensure that the generated PDF documents accurately reflect the original HTML rendering.

Beyond basic operations, IronPDF supports PDF forms, all-level encryption, and adding digital signatures. You can extract images and text from PDF files. You can also add text or HTML headers and footers, merge and split PDFs, modify multiple text segments, and find and replace text. IronPDF not only supports the creation of PDFs from HTML but also supports conversion to PDF from DOCX, RTF, MD, and image files. This library is very lightweight and very efficient for memory management (Less than 10MB of memory required for basic operations). IronPDF keeps track of its milestones regarding stability and performance that you can access from here.

IronPDF offers multiple levels of support. You can reach out to the engineers via live chat, ticket creation, or email. The support team is available 24/7. IronPDF also has detailed tutorials and documentation that cover nearly all topics you might need to understand or have questions about.

IronPDF is a production-ready library that has been tested, optimized, and trusted by many popular companies for their live products. This makes it one of the best PDF libraries to use in your projects for PDF operations. Let's have a look at the code examples of the IronPDF library.

Code Examples

Convert HTML to PDF

using IronPdf;
var renderer = new ChromePdfRenderer();

// 1. HTML String to PDF
var pdf1 = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf1.SaveAs("html-string.pdf");

// 2. HTML String with Assets (Images, CSS, JS)
var pdf2 = renderer.RenderHtmlAsPdf(
    "<img src='logo.png'><link rel='stylesheet' href='style.css'>",
    @"C:\assets\"
);
pdf2.SaveAs("html-with-assets.pdf");

// 3. HTML File to PDF
var pdf3 = renderer.RenderHtmlFileAsPdf("example.html");
pdf3.SaveAs("html-file.pdf");

// 4. URL to PDF
var pdf4 = renderer.RenderUrlAsPdf("https://ironpdf.com");
pdf4.SaveAs("url.pdf");
using IronPdf;
var renderer = new ChromePdfRenderer();

// 1. HTML String to PDF
var pdf1 = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
pdf1.SaveAs("html-string.pdf");

// 2. HTML String with Assets (Images, CSS, JS)
var pdf2 = renderer.RenderHtmlAsPdf(
    "<img src='logo.png'><link rel='stylesheet' href='style.css'>",
    @"C:\assets\"
);
pdf2.SaveAs("html-with-assets.pdf");

// 3. HTML File to PDF
var pdf3 = renderer.RenderHtmlFileAsPdf("example.html");
pdf3.SaveAs("html-file.pdf");

// 4. URL to PDF
var pdf4 = renderer.RenderUrlAsPdf("https://ironpdf.com");
pdf4.SaveAs("url.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Extract text and images from PDFs

using IronPdf;
using IronSoftware.Drawing;
using System.Collections.Generic;

// Load PDF document
var pdf = PdfDocument.FromFile("sample.pdf");

// 1. Extract All Text
string allText = pdf.ExtractAllText();

// 2. Extract Text from Specific Page
string pageText = pdf.ExtractTextFromPage(0); 

// 3. Extract Text from Multiple Pages
for (int i = 0; i < pdf.PageCount; i++)
{
    string text = pdf.ExtractTextFromPage(i);
    Console.WriteLine($"Page {i + 1}: {text}");
}

// 4. Extract All Images
var allImages = pdf.ExtractAllImages();
foreach (var image in allImages)
{
    image.SaveAs($"image_{allImages.IndexOf(image)}.png");
}

// 5. Extract Images from Specific Page
List<AnyBitmap> pageImages = pdf.ExtractBitmapsFromPage(0);

// 6. Extract Raw Images (as byte arrays)
var rawImages = pdf.ExtractAllRawImages();
for (int i = 0; i < rawImages.Count; i++)
{
    System.IO.File.WriteAllBytes($"raw_image_{i}.png", rawImages[i]);
}

// 7. Extract Both Text & Images from Each Page
for (int i = 0; i < pdf.PageCount; i++)
{
    string text = pdf.ExtractTextFromPage(i);
    List<AnyBitmap> images = pdf.ExtractBitmapsFromPage(i);

    Console.WriteLine($"Page {i + 1}: {text}");
    Console.WriteLine($"Found {images.Count} images");
}
using IronPdf;
using IronSoftware.Drawing;
using System.Collections.Generic;

// Load PDF document
var pdf = PdfDocument.FromFile("sample.pdf");

// 1. Extract All Text
string allText = pdf.ExtractAllText();

// 2. Extract Text from Specific Page
string pageText = pdf.ExtractTextFromPage(0); 

// 3. Extract Text from Multiple Pages
for (int i = 0; i < pdf.PageCount; i++)
{
    string text = pdf.ExtractTextFromPage(i);
    Console.WriteLine($"Page {i + 1}: {text}");
}

// 4. Extract All Images
var allImages = pdf.ExtractAllImages();
foreach (var image in allImages)
{
    image.SaveAs($"image_{allImages.IndexOf(image)}.png");
}

// 5. Extract Images from Specific Page
List<AnyBitmap> pageImages = pdf.ExtractBitmapsFromPage(0);

// 6. Extract Raw Images (as byte arrays)
var rawImages = pdf.ExtractAllRawImages();
for (int i = 0; i < rawImages.Count; i++)
{
    System.IO.File.WriteAllBytes($"raw_image_{i}.png", rawImages[i]);
}

// 7. Extract Both Text & Images from Each Page
for (int i = 0; i < pdf.PageCount; i++)
{
    string text = pdf.ExtractTextFromPage(i);
    List<AnyBitmap> images = pdf.ExtractBitmapsFromPage(i);

    Console.WriteLine($"Page {i + 1}: {text}");
    Console.WriteLine($"Found {images.Count} images");
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Edit PDF Documents: Headers & Footers

using IronPdf;
using System;
var renderer = new ChromePdfRenderer();

// 1. Add Footer with Page Numbers
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter()
{
    HtmlFragment = "<center><i>{page} of {total-pages}</i></center>",
    MaxHeight = 15, // mm
    DrawDividerLine = true
};
renderer.RenderingOptions.MarginBottom = 25;

// 2. Add Header with Logo
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
    HtmlFragment = "<img src='logo.png'>",
    MaxHeight = 20, // mm
    BaseUrl = new Uri(@"C:\assets\images\").AbsoluteUri
};
renderer.RenderingOptions.MarginTop = 25;

// 3. Render HTML to PDF
var pdf = renderer.RenderHtmlAsPdf("<h1>Document Title</h1><p>Content...</p>");
pdf.SaveAs("output.pdf");
using IronPdf;
using System;
var renderer = new ChromePdfRenderer();

// 1. Add Footer with Page Numbers
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter()
{
    HtmlFragment = "<center><i>{page} of {total-pages}</i></center>",
    MaxHeight = 15, // mm
    DrawDividerLine = true
};
renderer.RenderingOptions.MarginBottom = 25;

// 2. Add Header with Logo
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
    HtmlFragment = "<img src='logo.png'>",
    MaxHeight = 20, // mm
    BaseUrl = new Uri(@"C:\assets\images\").AbsoluteUri
};
renderer.RenderingOptions.MarginTop = 25;

// 3. Render HTML to PDF
var pdf = renderer.RenderHtmlAsPdf("<h1>Document Title</h1><p>Content...</p>");
pdf.SaveAs("output.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Form handling

using IronPdf;

// Load existing PDF with form fields
var pdf = PdfDocument.FromFile("EditableForm.pdf");

// Fill text fields
pdf.Form.FindFormField("firstname").Value = "John";
pdf.Form.FindFormField("lastname").Value = "Smith";
pdf.Form.FindFormField("email").Value = "john.smith@example.com";

// Fill radio button
pdf.Form.FindFormField("gender").Value = "Male";

// Fill dropdown/combobox
pdf.Form.FindFormField("country").Value = "USA";

// Fill checkbox ("Yes" to check, "No" to uncheck)
pdf.Form.FindFormField("subscribe").Value = "Yes";

// Fill textarea (use \r\n for line breaks)
pdf.Form.FindFormField("comments").Value = "This is a comment.\r\nSecond line here.";

// Save filled form
pdf.SaveAs("FilledForm.pdf");
using IronPdf;

// Load existing PDF with form fields
var pdf = PdfDocument.FromFile("EditableForm.pdf");

// Fill text fields
pdf.Form.FindFormField("firstname").Value = "John";
pdf.Form.FindFormField("lastname").Value = "Smith";
pdf.Form.FindFormField("email").Value = "john.smith@example.com";

// Fill radio button
pdf.Form.FindFormField("gender").Value = "Male";

// Fill dropdown/combobox
pdf.Form.FindFormField("country").Value = "USA";

// Fill checkbox ("Yes" to check, "No" to uncheck)
pdf.Form.FindFormField("subscribe").Value = "Yes";

// Fill textarea (use \r\n for line breaks)
pdf.Form.FindFormField("comments").Value = "This is a comment.\r\nSecond line here.";

// Save filled form
pdf.SaveAs("FilledForm.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

As you can see from the above examples, you can perform any operation on a PDF file with just a few lines using IronPDF. It is very simple and straightforward. Method names are easy to understand and implement.

License

IronPDF is free to use for development purposes, and you can download the free trial as well. But for the production, you will need to buy a license for IronPDF. IronPDF's licensing model is flexible, as it offers two types of licenses:

  1. Subscription License

  2. Perpetual License

Subscription License will cost you $59/month (billed annually), which includes 1 developer, 1 project, and 15,000 API calls per year. Additional API calls cost $0.03 each after your quota is exceeded.

Perpetual License starts from $749 and has multiple options, which you can choose according to your needs. The best part of this license is that it is a time payment. You don't have to pay again for using IronPDF.

Csharp Pdf Libraries Tool 1 related to License

2. Aspose.PDF for .NET

Aspose.PDF is also a C# PDF library developed by Aspose as part of their .NET library suite, which is widely used commercially for PDF-related tasks such as creating complex reports, sensitive documents, customizing PDF documents, and many more. It is one of the most commonly used PDF libraries for C#. It also supports the latest .NET Framework.

Aspose.PDF can create PDF documents not only from the HTML content, but also supports extracting data from the XML files to fulfill the real data instead of creating static files. This feature is very helpful for creating complex reports. Similar to IronPDF, you can add text, images, graphs, and many other types of content in PDF files. Aspose.PDF also offers digital signatures embedding, annotations handling, headers & footers, and extracting text from the PDF files. You can extract the structured data from a PDF. This library handles PDF editing very well by using the mentioned features.

Besides these pros of the Aspose.PDF library, there are multiple cons as well. The main drawback of this library is its very high price (Starting from $1679), and its pricing model is very complex to understand. Unlike IronPDF, you have to buy the model for each process separately, like development and deployment. Also, this library is very resource-consuming (exceeding 2GB when generating PDFs with 400+ images). It requires a lot of memory to tackle the PDF operations, and it is really frustrating. There is no doubt that this library is good at what it does, but it has a very steep learning curve. Its code is not easy to understand and requires a very detailed learning session to understand.

Code Example

Generate PDF documents with Text, Images, and Tables

using Aspose.Pdf;
using Aspose.Pdf.Text;

using (var document = new Document())
{
    // Add page objects
    var page = document.Pages.Add();

    // Add image - requires Rectangle positioning (You can add tiff images as well)
    page.AddImage("logo.png", new Rectangle(20, 730, 120, 830));

    // Add text - requires manual positioning
    var header = new TextFragment("Company Report");
    header.TextState.Font = FontRepository.FindFont("Arial");
    header.TextState.FontSize = 24;
    header.HorizontalAlignment = HorizontalAlignment.Center;
    header.Position = new Position(130, 720);
    page.Paragraphs.Add(header);

    // Add table - extensive configuration required
    var table = new Table
    {
        ColumnWidths = "100 100 100",
        Border = new BorderInfo(BorderSide.Box, 1f, Color.Black),
        DefaultCellBorder = new BorderInfo(BorderSide.Box, 0.5f, Color.Gray),
        DefaultCellPadding = new MarginInfo(4.5, 4.5, 4.5, 4.5)
    };

    // Add header row
    var headerRow = table.Rows.Add();
    headerRow.Cells.Add("Name");
    headerRow.Cells.Add("Age");
    headerRow.Cells.Add("City");

    // Style each header cell individually
    foreach (Cell cell in headerRow.Cells)
    {
        cell.BackgroundColor = Color.LightGray;
        cell.DefaultCellTextState.FontSize = 12;
    }

    // Add data row
    var dataRow = table.Rows.Add();
    dataRow.Cells.Add("John Doe");
    dataRow.Cells.Add("30");
    dataRow.Cells.Add("New York");

    page.Paragraphs.Add(table);

    // Save document
    document.Save("Report.pdf");
}
using Aspose.Pdf;
using Aspose.Pdf.Text;

using (var document = new Document())
{
    // Add page objects
    var page = document.Pages.Add();

    // Add image - requires Rectangle positioning (You can add tiff images as well)
    page.AddImage("logo.png", new Rectangle(20, 730, 120, 830));

    // Add text - requires manual positioning
    var header = new TextFragment("Company Report");
    header.TextState.Font = FontRepository.FindFont("Arial");
    header.TextState.FontSize = 24;
    header.HorizontalAlignment = HorizontalAlignment.Center;
    header.Position = new Position(130, 720);
    page.Paragraphs.Add(header);

    // Add table - extensive configuration required
    var table = new Table
    {
        ColumnWidths = "100 100 100",
        Border = new BorderInfo(BorderSide.Box, 1f, Color.Black),
        DefaultCellBorder = new BorderInfo(BorderSide.Box, 0.5f, Color.Gray),
        DefaultCellPadding = new MarginInfo(4.5, 4.5, 4.5, 4.5)
    };

    // Add header row
    var headerRow = table.Rows.Add();
    headerRow.Cells.Add("Name");
    headerRow.Cells.Add("Age");
    headerRow.Cells.Add("City");

    // Style each header cell individually
    foreach (Cell cell in headerRow.Cells)
    {
        cell.BackgroundColor = Color.LightGray;
        cell.DefaultCellTextState.FontSize = 12;
    }

    // Add data row
    var dataRow = table.Rows.Add();
    dataRow.Cells.Add("John Doe");
    dataRow.Cells.Add("30");
    dataRow.Cells.Add("New York");

    page.Paragraphs.Add(table);

    // Save document
    document.Save("Report.pdf");
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

You can see that the code required by Aspose.PDF to create new PDF documents is very complex. You've to manually set every coordinate in the code itself. You've to manually style each PDF object element, which is very time-consuming and not efficient. However, it provides granular control over the PDF documents.

License

Aspose.PDF has multiple licensing options, but most of them are pay-as-you-go. The license price starts from $1679. It is very costly compared to the IronPDF license options (starting from $749).

Csharp Pdf Libraries Tool 2 related to License

3. iTextSuite for .NET

iTextSuite (commonly known as iText7 & iTextSharp) is the SDK for PDF development offered by Apryse. It is a comprehensive suite that has all the necessary tools that we need to perform PDF operations in .NET applications. Similar to the above libraries, you can create, edit, redact, encrypt, and perform many other operations on PDF documents.

iTextSuite handles all creation and editing of PDF tasks very well, whether it is the creation of simple invoices or it involves the complex layouts of reports regarding finance modules. It is also not heavy on the system to use and can work flawlessly with heavy documents. It processes documents quickly and gives you output without any significant delay.

Alongside all these good features, there are some drawbacks to the iTextSuite as well, which you should know before considering this library. The cost of this library is reportedly very high compared to the alternatives present in the market. Its original pricing is not available on its pricing page. You've to contact customer support to get a quote. It offers an AGPL license as well, but it requires you to make your product open source when you use the AGPL-licensed iTextSuite. Similar to Aspose, it also has a steep learning curve and is not beginner-friendly. Advanced PDF manipulation requires a detailed understanding of PDF and the library's structure.

Code Example

Create a PDF document Table with Styling and Colors

using iText.Kernel.Colors;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;

public void CreateStyledTable(string dest)
{
    using var writer = new PdfWriter(dest);
    using var pdf = new PdfDocument(writer);
    var document = new Document(pdf);

    // Create a 2-column table
    Table table = new Table(2, false);

    // Header cells with gray background
    Cell cell11 = new Cell(1, 1)
        .SetBackgroundColor(ColorConstants.GRAY)
        .SetTextAlignment(TextAlignment.CENTER)
        .Add(new Paragraph("State"));

    Cell cell12 = new Cell(1, 1)
        .SetBackgroundColor(ColorConstants.GRAY)
        .SetTextAlignment(TextAlignment.CENTER)
        .Add(new Paragraph("Capital"));

    // Data cells
    Cell cell21 = new Cell(1, 1)
        .SetTextAlignment(TextAlignment.CENTER)
        .Add(new Paragraph("New York"));

    Cell cell22 = new Cell(1, 1)
        .SetTextAlignment(TextAlignment.CENTER)
        .Add(new Paragraph("Albany"));

    Cell cell31 = new Cell(1, 1)
        .SetTextAlignment(TextAlignment.CENTER)
        .Add(new Paragraph("New Jersey"));

    Cell cell32 = new Cell(1, 1)
        .SetTextAlignment(TextAlignment.CENTER)
        .Add(new Paragraph("Trenton"));

    // Add all cells to table
    table.AddCell(cell11);
    table.AddCell(cell12);
    table.AddCell(cell21);
    table.AddCell(cell22);
    table.AddCell(cell31);
    table.AddCell(cell32);

    document.Add(table);
    document.Close();
}
using iText.Kernel.Colors;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;

public void CreateStyledTable(string dest)
{
    using var writer = new PdfWriter(dest);
    using var pdf = new PdfDocument(writer);
    var document = new Document(pdf);

    // Create a 2-column table
    Table table = new Table(2, false);

    // Header cells with gray background
    Cell cell11 = new Cell(1, 1)
        .SetBackgroundColor(ColorConstants.GRAY)
        .SetTextAlignment(TextAlignment.CENTER)
        .Add(new Paragraph("State"));

    Cell cell12 = new Cell(1, 1)
        .SetBackgroundColor(ColorConstants.GRAY)
        .SetTextAlignment(TextAlignment.CENTER)
        .Add(new Paragraph("Capital"));

    // Data cells
    Cell cell21 = new Cell(1, 1)
        .SetTextAlignment(TextAlignment.CENTER)
        .Add(new Paragraph("New York"));

    Cell cell22 = new Cell(1, 1)
        .SetTextAlignment(TextAlignment.CENTER)
        .Add(new Paragraph("Albany"));

    Cell cell31 = new Cell(1, 1)
        .SetTextAlignment(TextAlignment.CENTER)
        .Add(new Paragraph("New Jersey"));

    Cell cell32 = new Cell(1, 1)
        .SetTextAlignment(TextAlignment.CENTER)
        .Add(new Paragraph("Trenton"));

    // Add all cells to table
    table.AddCell(cell11);
    table.AddCell(cell12);
    table.AddCell(cell21);
    table.AddCell(cell22);
    table.AddCell(cell31);
    table.AddCell(cell32);

    document.Add(table);
    document.Close();
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

From the above example, you can understand the complexity of the code for iTextSuite. It increases development time and complexity for building big applications.

License

iTextSuite offers two license models. One is commercial and the other is an AGPL license. You can use iTextSuite in production for free under the AGPL license, but you'll need to open source your product as well. Regarding the commercial license, there is no price mentioned on the license page. You'll need to request a quote, or you can contact customer support.

Csharp Pdf Libraries Tool 3 related to License

4. PDFSharp

PDFSharp is a C# open-source solution for PDF problems that developers face when performing PDF operations programmatically. It supports the latest .NET frameworks, including .NET Core as well. It's a lightweight solution that covers all the basic needs of a developer regarding PDFs.

PDFSharp can handle most common PDF operations with ease. You can create documents, insert images, draw shapes, and edit text fonts and sizes. You can put anything at any position, as PDFSharp gives you full control over the PDF.

However, PDFSharp has certain limitations that you should know. It doesn't support HTML to PDF conversion natively, and it's a big drawback for developers because HTML makes it very easy for styling and positioning in PDFs. Its performance is affected when it has to process multiple large files. You can't perform complex operations like encryption and form filling. And it lacks official support channels. You rely only on the community or your own problem-solving skills if you face any issues while working with this library.

Code Example

Creating a PDF with Multiple Text Styles

using PdfSharp.Pdf;
using PdfSharp.Drawing;

// Create document
PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);

// Example of different font styles
XFont regularFont = new XFont("Arial", 12, XFontStyleEx.Regular);
XFont boldFont = new XFont("Arial", 12, XFontStyleEx.Bold);
XFont italicFont = new XFont("Arial", 12, XFontStyleEx.Italic);
XFont boldItalicFont = new XFont("Arial", 12, XFontStyleEx.BoldItalic);

// Position for the first text
double y = 50;
double x = 50;
double lineHeight = 20;

// Draw text in different styles - REQUIRES manual positioning
gfx.DrawString("Regular text in Arial", regularFont, XBrushes.Black, x, y);
y += lineHeight;
gfx.DrawString("Bold text in Arial", boldFont, XBrushes.Black, x, y);
y += lineHeight;
gfx.DrawString("Italic text in Arial", italicFont, XBrushes.Black, x, y);
y += lineHeight;
gfx.DrawString("Bold and Italic text in Arial", boldItalicFont, XBrushes.Black, x, y);

// Save document
document.Save("FormattedText.pdf");
using PdfSharp.Pdf;
using PdfSharp.Drawing;

// Create document
PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);

// Example of different font styles
XFont regularFont = new XFont("Arial", 12, XFontStyleEx.Regular);
XFont boldFont = new XFont("Arial", 12, XFontStyleEx.Bold);
XFont italicFont = new XFont("Arial", 12, XFontStyleEx.Italic);
XFont boldItalicFont = new XFont("Arial", 12, XFontStyleEx.BoldItalic);

// Position for the first text
double y = 50;
double x = 50;
double lineHeight = 20;

// Draw text in different styles - REQUIRES manual positioning
gfx.DrawString("Regular text in Arial", regularFont, XBrushes.Black, x, y);
y += lineHeight;
gfx.DrawString("Bold text in Arial", boldFont, XBrushes.Black, x, y);
y += lineHeight;
gfx.DrawString("Italic text in Arial", italicFont, XBrushes.Black, x, y);
y += lineHeight;
gfx.DrawString("Bold and Italic text in Arial", boldItalicFont, XBrushes.Black, x, y);

// Save document
document.Save("FormattedText.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

PDFSharp remains a solid choice for developers who need a lightweight, free solution for basic PDF generation with precise positioning control. Just be prepared to work around its limitations or add it with other tools for more advanced requirements.

License

PDFSharp is distributed under the MIT License and is completely free to use. You just need to include the original copyright notice and mention the license in your distribution.

5. PDFPig

PDFPig is another open source library built for .NET developers that lets you read and extract content from PDF files. This library extracts the position and size of individual letters from PDF documents. It retrieves images, reads PDF annotations and forms, accesses hyperlinks, and exposes embedded documents. You can also access document metadata and view the internal PDF structure.

The library performs well in benchmarks compared to similar .NET tools and uses memory efficiently. It provides a no-cost alternative to commercial options. It receives regular updates and maintains active GitHub documentation.

The library has clear limitations you should know about. It does not convert HTML or other formats to PDF. It cannot generate images from PDF pages, though separate tools like docnet or PDFtoImage can fill that gap. PDF forms are read-only; you cannot modify or add form values. For table extraction, you need external tools like Tabula Sharp or Camelot Sharp. You cannot add or edit hyperlinks when building documents. Compared to more comprehensive libraries like IronPDF, PDFPig offers fewer features and less extensive documentation.

Code Example

Basic Text Extraction

using System;
using System.Collections.Generic;
using System.Linq;
using UglyToad.PdfPig;
using UglyToad.PdfPig.Content;

public static class Program
{
    public static void Main()
    {
        using (PdfDocument document = PdfDocument.Open(@"C:\path\to\file.pdf"))
        {
            foreach (Page page in document.GetPages())
            {
                // Extract all letters
                IReadOnlyList<Letter> letters = page.Letters;
                string text = string.Join(string.Empty, letters.Select(x => x.Value));

                // Extract words
                IEnumerable<Word> words = page.GetWords();

                // Extract images
                IEnumerable<IPdfImage> images = page.GetImages();
            }
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using UglyToad.PdfPig;
using UglyToad.PdfPig.Content;

public static class Program
{
    public static void Main()
    {
        using (PdfDocument document = PdfDocument.Open(@"C:\path\to\file.pdf"))
        {
            foreach (Page page in document.GetPages())
            {
                // Extract all letters
                IReadOnlyList<Letter> letters = page.Letters;
                string text = string.Join(string.Empty, letters.Select(x => x.Value));

                // Extract words
                IEnumerable<Word> words = page.GetWords();

                // Extract images
                IEnumerable<IPdfImage> images = page.GetImages();
            }
        }
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

License

PDFPig is distributed under the Apache 2.0 License, which only requires you to include the original copyright notice and license text in your distributions. Beyond this requirement, you are completely free to use this library in any manner.

Conclusion

In summary, let's compare the pricing and licensing models of these C# PDF libraries.

IronPDF offers flexible pricing plans suitable for individuals and companies alike. It's free for development purposes and includes a free trial. The pricing is very reasonable, starting from just $749. With its comprehensive feature set, excellent support, and production-ready stability, IronPDF delivers the best value for money.

Aspose.PDF follows a pay-as-you-go model with licensing starting at $1679, and it is significantly more expensive than alternatives. While it offers granular control, the steep learning curve and high costs may not suit all budgets.

iTextSuite does not publish transparent pricing on its website. You must contact their support team for a quote, which means pricing varies case by case. They do offer an AGPL license for free use, but this requires you to open source your entire product.

PDFSharp and PDFPig are completely free under the MIT and Apache 2.0 licenses, respectively. However, their functionality is limited compared to commercial options. PDFSharp lacks HTML to PDF conversion and struggles with large files, while PDFPig is primarily a read-only library.

Choosing the right PDF library depends on your specific needs and budget. If you need basic operations and have technical expertise, open source options work well. However, for extensive features feature-rich applications requiring advanced features, reliable support, and comprehensive documentation, IronPDF stands out as the most cost-effective and feature-complete solution.