Skip to footer content
PRODUCT COMPARISONS

How to Create a PDF with Aspose C# VS IronPDF

Creating PDF files programmatically is essential for modern .NET applications, whether generating invoices, reports, or converting web content to PDF format. This tutorial explores how to create PDF using Aspose C# and IronPDF, providing complete code examples to help developers choose the right library for their needs.

How to Create a PDF with Aspose C# VS IronPDF: Figure 1

Prerequisites

Before starting to create a PDF file, ensure you have:

  • .NET Framework 4.6.2+ or .NET Core 3.1+
  • Visual Studio 2019 or compatible IDE
  • Basic knowledge of using C# programming

Installation

How to Create a PDF with Aspose C# VS IronPDF: Figure 2

Installing Aspose PDF via Package Manager Console

Open the Package Manager Console in Visual Studio and run the following command:

Install-Package Aspose.PDF

How to Create a PDF with Aspose C# VS IronPDF: Figure 3 - Aspose.PDF Installation

Installing IronPDF

Use the same method to install the package IronPDF:

Install-Package IronPdf

How to Create a PDF with Aspose C# VS IronPDF: Figure 4 - Installation

Note: IronPDF includes an embedded Chrome engine for superior HTML rendering, with support for Windows, Linux, macOS, Docker containers, and cloud platforms.

How to Create a PDF with Aspose C# VS IronPDF: Figure 5 - Create PDF - IronPDF

Creating Your First PDF Document

Let's create PDF files with both libraries to understand their fundamental approaches. These code snippet examples demonstrate the basic logic for PDF generation.

Create a PDF Using Aspose PDF for .NET API

using Aspose.Pdf;
using Aspose.Pdf.Text;
// Create new instance of Document class
var document = new Aspose.Pdf.Document();
// Add pages to the document object
var page = document.Pages.Add();
// Create new TextFragment with Hello World text
var textFragment = new TextFragment("Hello World!");
textFragment.TextState.FontSize = 24;
// Add text to paragraphs collection
page.Paragraphs.Add(textFragment);
// Save the generated PDF document
document.Save("output.pdf");
using Aspose.Pdf;
using Aspose.Pdf.Text;
// Create new instance of Document class
var document = new Aspose.Pdf.Document();
// Add pages to the document object
var page = document.Pages.Add();
// Create new TextFragment with Hello World text
var textFragment = new TextFragment("Hello World!");
textFragment.TextState.FontSize = 24;
// Add text to paragraphs collection
page.Paragraphs.Add(textFragment);
// Save the generated PDF document
document.Save("output.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This source code creates PDF documents by building a document object model. You create a new document, add pages to the collection, and then add content to those pages. The Aspose.Pdf.Document class provides the foundation, while paragraphs hold your content. For testing purposes, this Hello World example demonstrates the basic process.

Output

How to Create a PDF with Aspose C# VS IronPDF: Figure 6 - PDF Output

Creating PDFs with IronPDF

using IronPdf;
// Create new instance of ChromePdfRenderer
var renderer = new ChromePdfRenderer();
// Convert HTML string to PDF file
var html = "<h1>Hello World!</h1>";
var pdf = renderer.RenderHtmlAsPdf(html);
// Save PDF files using SaveAs method
pdf.SaveAs("output.pdf");
using IronPdf;
// Create new instance of ChromePdfRenderer
var renderer = new ChromePdfRenderer();
// Convert HTML string to PDF file
var html = "<h1>Hello World!</h1>";
var pdf = renderer.RenderHtmlAsPdf(html);
// Save PDF files using SaveAs method
pdf.SaveAs("output.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

IronPDF takes a different approach to create a PDF - it renders HTML directly to PDF format using Chrome. This API allows you to convert web content and implement complex layouts easily. The library handles all rendering complexities, making it simpler to accomplish professional results.

Output

How to Create a PDF with Aspose C# VS IronPDF: Figure 7 - IronPDF Output

Real-World Example: Creating an Invoice

Here's complete code to create PDF files using both libraries for a practical invoice solution.

Invoice with New Aspose PDF

// Create new Document instance
var document = new Document();
var page = document.Pages.Add();
// Add title text
var title = new TextFragment("INVOICE");
title.TextState.FontSize = 28;
title.HorizontalAlignment = HorizontalAlignment.Center;
// Add to paragraphs
page.Paragraphs.Add(title);
// Create table object for invoice items
var table = new Table();
table.ColumnWidths = "200 100 100";
// Add header row to table
var headerRow = table.Rows.Add();
headerRow.Cells.Add("Description");
headerRow.Cells.Add("Quantity"); 
headerRow.Cells.Add("Price");
// Add data rows
var dataRow = table.Rows.Add();
dataRow.Cells.Add("Product A");
dataRow.Cells.Add("2");
dataRow.Cells.Add("$50.00");
// Add table to page paragraphs
page.Paragraphs.Add(table);
// Save the PDF document
document.Save("invoice.pdf");
// Create new Document instance
var document = new Document();
var page = document.Pages.Add();
// Add title text
var title = new TextFragment("INVOICE");
title.TextState.FontSize = 28;
title.HorizontalAlignment = HorizontalAlignment.Center;
// Add to paragraphs
page.Paragraphs.Add(title);
// Create table object for invoice items
var table = new Table();
table.ColumnWidths = "200 100 100";
// Add header row to table
var headerRow = table.Rows.Add();
headerRow.Cells.Add("Description");
headerRow.Cells.Add("Quantity"); 
headerRow.Cells.Add("Price");
// Add data rows
var dataRow = table.Rows.Add();
dataRow.Cells.Add("Product A");
dataRow.Cells.Add("2");
dataRow.Cells.Add("$50.00");
// Add table to page paragraphs
page.Paragraphs.Add(table);
// Save the PDF document
document.Save("invoice.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

The Aspose PDF NET API requires building each element programmatically. You create the document object, add pages, and then add content to the paragraphs collection. This gives you precise control but requires more code to accomplish complex layouts.

Invoice with IronPDF

var renderer = new ChromePdfRenderer();
// Configure PDF output settings
renderer.RenderingOptions.MarginTop = 25;
renderer.RenderingOptions.MarginBottom = 25;
// HTML string with invoice content
var html = @"
<html>
<head>
    <style>
        table { width: 100%; }
        th, td { padding: 8px; }
    </style>
</head>
<body>
    <h1>INVOICE</h1>
    <table>
        <tr>
            <th>Description</th>
            <th>Quantity</th>
            <th>Price</th>
        </tr>
        <tr>
            <td>Product A</td>
            <td>2</td>
            <td>$50.00</td>
        </tr>
    </table>
</body>
</html>";
// Generate PDF from HTML
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("invoice.pdf");
var renderer = new ChromePdfRenderer();
// Configure PDF output settings
renderer.RenderingOptions.MarginTop = 25;
renderer.RenderingOptions.MarginBottom = 25;
// HTML string with invoice content
var html = @"
<html>
<head>
    <style>
        table { width: 100%; }
        th, td { padding: 8px; }
    </style>
</head>
<body>
    <h1>INVOICE</h1>
    <table>
        <tr>
            <th>Description</th>
            <th>Quantity</th>
            <th>Price</th>
        </tr>
        <tr>
            <td>Product A</td>
            <td>2</td>
            <td>$50.00</td>
        </tr>
    </table>
</body>
</html>";
// Generate PDF from HTML
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("invoice.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

With IronPDF, you write standard HTML and the system handles rendering. This method makes it easier to create PDF files with professional layouts. You can reference external stylesheets, add images, and include links.

Output

How to Create a PDF with Aspose C# VS IronPDF: Figure 8 - IronPDF Invoice Output

Advanced Features

Converting Web Pages to PDF Files Using IronPDF

// Load and convert URL to PDF
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com");
pdf.SaveAs("website.pdf");
// Load and convert URL to PDF
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com");
pdf.SaveAs("website.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Adding Security to Generated PDF

// Create PDF document
var pdf = renderer.RenderHtmlAsPdf(html);
// Implement security settings
pdf.SecuritySettings.UserPassword = "user123";
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
// Save secured file
pdf.SaveAs("secured.pdf");
// Create PDF document
var pdf = renderer.RenderHtmlAsPdf(html);
// Implement security settings
pdf.SecuritySettings.UserPassword = "user123";
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
// Save secured file
pdf.SaveAs("secured.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

IronPDF provides intuitive methods to add security, headers, footers, and other features to your PDF documents. You can also delete pages, merge files, or extract content.

Output

How to Create a PDF with Aspose C# VS IronPDF: Figure 9 - IronPDF Secure PDF Output

Choosing the Right Library

When to Use IronPDF

IronPDF excels when you:

  • Need to convert HTML to PDF format
  • Want simpler code and faster development
  • Require JavaScript execution
  • Need cross-platform support
  • Deploy to Docker or cloud environment

How to Create a PDF with Aspose C# VS IronPDF: Figure 10 - Features

When to Use Aspose PDF

Aspose PDF for .NET applications works well when:

  • Creating PDFs from scratch programmatically
  • Need granular control over document object model
  • Working with complex PDF manipulations
  • Importing existing PDF files for processing

License Comparison

IronPDF offers straightforward licensing starting at $749, including support and updates. The free trial includes all features without watermarks.

How to Create a PDF with Aspose C# VS IronPDF: Figure 11 - Licensing

Aspose PDF starts at $1,199 with additional costs for support. Both libraries offer evaluation versions for testing purposes.

Conclusion

Both libraries effectively create PDF documents in C#. Aspose PDF provides granular control through its document object model and TextFragment class, while IronPDF shines with HTML-to-PDF conversion using familiar web technologies.

For most modern .NET applications, IronPDF offers better value with its intuitive API, superior HTML rendering, included support, and the ability to create PDF files using simple code. Whether you need to load web pages, add images like BMP, or implement complex layouts, IronPDF's Chrome-based function streamlines the process.

Note for developers: IronPDF also includes Drawing capabilities and can reproduce complex designs. For questions, contact their engineering team or search their documentation to resolve any issues.

Start with IronPDF's free trial to evaluate how it can accomplish your PDF generation needs. Access all features to create, convert, and manipulate PDF files in your .NET solution.

Please noteAspose is a registered trademark of its respective owner. This site is not affiliated with, endorsed by, or sponsored by Aspose. All product names, logos, and brands are property of their respective owners. Comparisons are for informational purposes only and reflect publicly available information at the time of writing.

Frequently Asked Questions

What are the main features of IronPDF for creating PDFs?

IronPDF offers features such as HTML to PDF conversion, merging PDFs, and adding headers and footers. It is designed to be easy to use within .NET applications.

How does Aspose C# compare to IronPDF in terms of ease of use?

IronPDF is often praised for its intuitive API and straightforward integration with .NET applications, making it a preferred choice for developers seeking simplicity.

Can IronPDF handle large-scale PDF generation efficiently?

Yes, IronPDF is optimized for performance and can handle large-scale PDF generation efficiently, making it suitable for enterprise-level applications.

Does IronPDF support PDF manipulation such as merging or splitting?

IronPDF supports various PDF manipulations, including merging, splitting, and modifying existing PDFs, offering a versatile solution for developers.

Is there a difference in licensing models between Aspose C# and IronPDF?

Yes, IronPDF offers flexible licensing options, including perpetual and subscription models, which may differ from Aspose's offerings.

What type of applications can benefit from using IronPDF?

IronPDF is ideal for applications that require dynamic PDF generation, such as reporting systems, invoicing, and document management solutions.

How does IronPDF handle security features in PDFs?

IronPDF includes security features such as password protection and encryption, ensuring that generated PDFs are secure and adhere to data protection standards.

Are there any specific system requirements for using IronPDF?

IronPDF is compatible with .NET Framework and .NET Core, but specific system requirements depend on the version being used and the application environment.

Can IronPDF convert web pages into PDF format?

Yes, IronPDF can convert HTML web pages into PDF format, including support for complex layouts and styles.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More