.NET HELP

C# PDF NuGet (How it Works for Developers)

Published April 19, 2023
Share:

In the modern world of digital documentation, handling PDF documents has become increasingly important. Whether it's converting HTML to PDF documents, PDF encryption, managing NuGet package using Package Manager Console in Visual Studio, or utilizing the .NET Standard 2.0 framework/.NET Core 2.0, developers need a robust and efficient PDF file library. This article will introduce IronPDF, a comprehensive .NET/Core PDF library compatible with .NET Core 2.0, .NET Framework 7, .NET 6.0 and other .NET platforms, and explore its features and benefits.

Introduction of NuGet

NuGet is the package manager for .NET developers, making it easy to manage and include libraries and packages in projects. It simplifies the process of finding, installing, and managing third-party libraries, ensuring version compatibility and streamlining development workflows. NuGet packages can be installed via Visual Studio or through the Package Manager Console.

IronPDF: C# PDF Library

C# PDF NuGet (How It Works For Developers): Figure 2 - IronPDF- Create a PDF

IronPDF is a powerful and easy-to-use .NET PDF library designed to facilitate the creation, modification, and conversion of PDFs. It is available as a NuGet package. It offers a wide range of functionalities, including HTML files to PDF conversion, editing PDF documents, and watermarking. IronPDF is compatible with .NET Core, .NET Framework 4.0+, and other .NET platforms, making it the ideal choice for developers working with PDF files in their projects.

Compatibility of IronPDF

IronPDF is a highly compatible and adaptable .NET PDF conversion library that seamlessly integrates with various .NET platforms. This broad compatibility ensures that developers can effortlessly incorporate IronPDF into their existing projects, regardless of the platform they are using.

C# PDF NuGet (How It Works For Developers): Figure 3 - Cross Platform

.NET Standard 2.0: As a .NET Standard 2.0 compliant library, IronPDF allows developers to create cross-platform applications targeting multiple .NET implementations. Its compatibility with .NET Standard 2.0 means that developers can leverage IronPDF's features in .NET Core, .NET Framework, and Xamarin projects, among others.

.NET Core 7.0: IronPDF's compatibility with .NET Core 7.0 ensures that developers can utilize it in modern, high-performance applications. .NET Core is an open-source, cross-platform framework designed for creating cloud-based and containerized applications, and IronPDF's support for this platform ensures developers can leverage its capabilities in a wide range of scenarios.

.NET Framework 7.0: IronPDF is also compatible with the .NET Framework 7.0, allowing developers to integrate its powerful PDF functionalities into legacy projects built on this popular framework. As .NET Framework remains widely used in enterprise environments, IronPDF's compatibility with version 7.0 and newer ensures that developers can continue to maintain and enhance existing applications with ease.

Install with NuGet Package Manager

IronPDF is an essential .NET PDF library that simplifies working with PDF files and web pages in .NET applications. To install IronPDF on a Windows computer using the NuGet Package Manager, follow these steps within Visual Studio:

  1. Open Visual Studio and navigate to your desired project.
  2. Go to the "Tools" menu, then select "NuGet Package Manager," followed by "Package Manager Console." This will open the Package Manager Console window.
  3. In the console, enter the following command to install package:

    Install-package IronPdf
  4. Press "Enter" to execute the command, and Visual Studio will download and install the latest version of IronPDF, incorporating it into your project.

To stay informed about the latest version updates or service status of nuget.org, check the IronPDF NuGet page or subscribe to release notifications. Version updates usually include new features, performance improvements, and bug fixes, ensuring that you're always using the most robust and efficient version of IronPDF.

IronPDF also offers specific NuGet packages for deployment on Linux and macOS. These packages are designed to simplify the process of deploying your application on non-Windows platforms.

Features of IronPDF

IronPDF boasts an array of features that cater to the diverse needs of developers working with PDF documents. These features include:

Convert HTML to PDF in C#

IronPDF allows developers to easily convert HTML content, including CSS and JavaScript, to high-quality PDF files. The following code example demonstrates how to create a PDF from an HTML string using C# and no Adobe Acrobat:


    using IronPdf;

    // Instantiate Renderer
    var renderer = new ChromePdfRenderer();

    // Create a PDF from a HTML string using C#
    var pd = renderer.RenderHtmlAsPdf("Hello World");

    // Export to a file or Stream
    pd.SaveAs("output.pdf");

    using IronPdf;

    // Instantiate Renderer
    var renderer = new ChromePdfRenderer();

    // Create a PDF from a HTML string using C#
    var pd = renderer.RenderHtmlAsPdf("Hello World");

    // Export to a file or Stream
    pd.SaveAs("output.pdf");
Imports IronPdf

	' Instantiate Renderer
	Private renderer = New ChromePdfRenderer()

	' Create a PDF from a HTML string using C#
	Private pd = renderer.RenderHtmlAsPdf("Hello World")

	' Export to a file or Stream
	pd.SaveAs("output.pdf")
VB   C#

C# PDF NuGet (How It Works For Developers): Figure 4 - HTML to PDF Output

Edit PDF

With IronPDF, developers can edit PDF documents, add or remove pages, and manipulate the content within the documents. The following code example demonstrates how to split a PDF document into separate files based on page breaks:


    using IronPdf;

    const string html =
        @" Hello Iron 
         This is 1st Page 

         This is 2nd Page

         This is 3rd Page";

    var renderer = new ChromePdfRenderer();
    var pdf = renderer.RenderHtmlAsPdf(html);

    // Take the first page
    var page1doc = pdf.CopyPage(0);
    page1doc.SaveAs("Split1.pdf");

    // Take the pages 2 & 3
    var page23doc = pdf.CopyPages(1, 2);
    page23doc.SaveAs("Split2.pdf");

    using IronPdf;

    const string html =
        @" Hello Iron 
         This is 1st Page 

         This is 2nd Page

         This is 3rd Page";

    var renderer = new ChromePdfRenderer();
    var pdf = renderer.RenderHtmlAsPdf(html);

    // Take the first page
    var page1doc = pdf.CopyPage(0);
    page1doc.SaveAs("Split1.pdf");

    // Take the pages 2 & 3
    var page23doc = pdf.CopyPages(1, 2);
    page23doc.SaveAs("Split2.pdf");
Imports IronPdf

	Private Const html As String = " Hello Iron 
         This is 1st Page 

         This is 2nd Page

         This is 3rd Page"

	Private renderer = New ChromePdfRenderer()
	Private pdf = renderer.RenderHtmlAsPdf(html)

	' Take the first page
	Private page1doc = pdf.CopyPage(0)
	page1doc.SaveAs("Split1.pdf")

	' Take the pages 2 & 3
	Dim page23doc = pdf.CopyPages(1, 2)
	page23doc.SaveAs("Split2.pdf")
VB   C#

C# PDF NuGet (How It Works For Developers): Figure 5 - Split Output

Security of PDF documents

IronPDF offers robust security features, including encryption, password protection, and digital signatures. The following code example demonstrates how to apply encryption and password protection to a PDF document:


    using IronPdf;

    // Load an existing PDF document
    var pdf = PdfDocument.FromFile("input.pdf");

    // Set encryption and password protection
    pdf.Encrypt(PdfDocument.EncryptionAlgorithm.AES, 256, "ownerPassword", "userPassword");

    // Save the encrypted PDF document
    pdf.SaveAs("encrypted_output.pdf");

    using IronPdf;

    // Load an existing PDF document
    var pdf = PdfDocument.FromFile("input.pdf");

    // Set encryption and password protection
    pdf.Encrypt(PdfDocument.EncryptionAlgorithm.AES, 256, "ownerPassword", "userPassword");

    // Save the encrypted PDF document
    pdf.SaveAs("encrypted_output.pdf");
Imports IronPdf

	' Load an existing PDF document
	Private pdf = PdfDocument.FromFile("input.pdf")

	' Set encryption and password protection
	pdf.Encrypt(PdfDocument.EncryptionAlgorithm.AES, 256, "ownerPassword", "userPassword")

	' Save the encrypted PDF document
	pdf.SaveAs("encrypted_output.pdf")
VB   C#

PDF Metadata

IronPDF enables developers to edit and manage the metadata of PDF documents, such as author, keywords, and modified date. The following code example demonstrates how to modify the metadata of an existing PDF:


    using IronPdf;

    // Open an Encrypted File, alternatively create a new PDF from HTML
    var pdf = PdfDocument.FromFile("encrypted.pdf", "password");

    // Edit file metadata
    pdf.MetaData.Author = "Satoshi Nakamoto";
    pdf.MetaData.Keywords = "SEO, Friendly";
    pdf.MetaData.ModifiedDate = System.DateTime.Now;

    using IronPdf;

    // Open an Encrypted File, alternatively create a new PDF from HTML
    var pdf = PdfDocument.FromFile("encrypted.pdf", "password");

    // Edit file metadata
    pdf.MetaData.Author = "Satoshi Nakamoto";
    pdf.MetaData.Keywords = "SEO, Friendly";
    pdf.MetaData.ModifiedDate = System.DateTime.Now;
Imports System
Imports IronPdf

	' Open an Encrypted File, alternatively create a new PDF from HTML
	Private pdf = PdfDocument.FromFile("encrypted.pdf", "password")

	' Edit file metadata
	pdf.MetaData.Author = "Satoshi Nakamoto"
	pdf.MetaData.Keywords = "SEO, Friendly"
	pdf.MetaData.ModifiedDate = DateTime.Now
VB   C#

Watermark

IronPDF allows developers to add watermarks to their PDF documents, enhancing security and branding. The following code example demonstrates how to stamp a watermark onto a new or existing PDF:


    using IronPdf;

    // Stamps a Watermark onto a new or existing PDF
    var renderer = new ChromePdfRenderer();

    var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
    pdf.ApplyWatermark("SAMPLE", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);
    pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");

    using IronPdf;

    // Stamps a Watermark onto a new or existing PDF
    var renderer = new ChromePdfRenderer();

    var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
    pdf.ApplyWatermark("SAMPLE", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);
    pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");
Imports IronPdf

	' Stamps a Watermark onto a new or existing PDF
	Private renderer = New ChromePdfRenderer()

	Private pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
	pdf.ApplyWatermark("SAMPLE", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center)
	pdf.SaveAs("C:\Path\To\Watermarked.pdf")
VB   C#

C# PDF NuGet (How It Works For Developers): Figure 6 - Watermark Output

Conclusion

IronPDF is a versatile and powerful .NET library that simplifies the process of working with PDF documents in .NET projects. With its extensive features, such as HTML to PDF conversion, PDF modification, security, metadata management, and watermarking, IronPDF is an invaluable asset for developers looking to enhance their applications and improve productivity. Compatible with .NET Standard 2.0, .NET Core 7.0, and .NET Framework 7.0, IronPDF can be easily integrated into existing projects through NuGet, making it a must-have tool for developers working with PDF files.

IronPDF offers a free trial for its software library, which allows users to test out its features and functionality before committing to a purchase. After the free trial period, users can choose to purchase a license for IronPDF, which starts at $749. The pricing for IronPDF depends on the type of license and the number of developers who will be using the software.

< PREVIOUS
How to use .NET Fiddle in C#
NEXT >
Razor Components : How it Works for Developers

Ready to get started? Version: 2024.10 just released

Free NuGet Download Total downloads: 11,308,499 View Licenses >