.NET HELP

NuGet HTML to PDF (Developer Tutorial)

Updated April 19, 2023
Share:

Introduction

In today's digital world, working with PDFs is a critical aspect of managing documents across various platforms. With the IronPDF library, developers have a powerful tool that helps create and manipulate PDF files using HTML, CSS, and JavaScript. In this article, we will explore the IronPDF NuGet library, which simplifies the process of generating PDFs in .NET applications.

What is NuGet

NuGet is a package manager for .NET developers, allowing them to easily find, install, and manage open-source libraries and dependencies in their projects. It streamlines the process of integrating third-party code, ensuring compatibility and reducing development time.

Introduction of IronPDF

NuGet HTML to PDF (Developer Tutorial): Figure 2

IronPDF is a popular C# PDF Library which is available as a NuGet package. It enables developers to generate, edit, and extract PDF content in .NET applications. With its easy-to-use methods, IronPDF allows you to create PDFs from HTML, URLs, or existing files, and provides additional features like merging, splitting, and watermarking PDFs.

How to Install IronPDF

Installing IronPDF is a straightforward process when using the NuGet Package Manager. To get started, open your .NET project in Visual Studio and navigate to the Solution Explorer. From there, right-click on your project and select "Manage NuGet Packages."

In the NuGet Package Manager window, switch to the Browse tab and search for "IronPDF." Once you've located the package, select it, and click on the "Install" button to begin the installation process. The package manager will guide you through the installation process with a series of prompts, including accepting the license agreement.

After completing the installation process, IronPDF will be added to your project, and you can start using it to generate PDF documents from your .NET application.

Convert an HTML String to a PDF

One of the core features of IronPDF is the ability to convert HTML strings to PDF documents. This can be done using the ChromePdfRenderer class, as shown in the code snippet below. It'll create a PDF page that contains the text.


    using IronPdf;

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

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

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

    using IronPdf;

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

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

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

	' Instantiate Renderer
	Private renderer = New ChromePdfRenderer()

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

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

NuGet HTML to PDF (Developer Tutorial): Figure 3 -

Convert a URL to a PDF

IronPDF also allows you to create a PDF from a URL, making it easy to convert webpages to PDFs.


    using IronPdf;

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

    // Create a PDF from a URL or local file path
    var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");

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

    using IronPdf;

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

    // Create a PDF from a URL or local file path
    var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");

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

	' Instantiate Renderer
	Private renderer = New ChromePdfRenderer()

	' Create a PDF from a URL or local file path
	Private pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/")

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

Convert an HTML Page to a PDF

Converting existing HTML files to PDFs is straightforward with IronPDF. Just use the RenderHtmlFileAsPdf method to create a PDF document from an HTML document.


    using IronPdf;

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

    // Create a PDF from an existing HTML file using C#
    var pdf = renderer.RenderHtmlFileAsPdf("example.html");

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

    using IronPdf;

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

    // Create a PDF from an existing HTML file using C#
    var pdf = renderer.RenderHtmlFileAsPdf("example.html");

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

	' Instantiate Renderer
	Private renderer = New ChromePdfRenderer()

	' Create a PDF from an existing HTML file using C#
	Private pdf = renderer.RenderHtmlFileAsPdf("example.html")

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

Other Features of IronPDF

Apart from generating PDFs, IronPDF offers additional features that cater to various document processing needs, including:

Merging and Splitting PDFs: Easily combine multiple PDFs into a single document or split an existing PDF into separate files based on the desired number of pages or page ranges.

Adding Headers, Footers, and Watermarks: Customize a PDF file by adding headers, footers, or watermarks, which can include text, images, or both. Maintain consistency and branding across your documents while providing essential information.

Form-filling and Extraction: IronPDF allows you to fill out PDF forms programmatically and extract data from filled forms. This feature simplifies the process of working with form-based PDFs, automating data entry and extraction tasks.

PDF Encryption and Security: Ensure the security of your PDFs by applying encryption, setting password protection, and defining user permissions for actions such as printing, editing, or content extraction.

Text and Image Extraction: IronPDF enables you to extract text and images from PDF documents, making it easier to repurpose content or perform further analysis.

Pagination and Styling using CSS: Customize the appearance of your PDFs using CSS to style text, images, and layout elements. IronPDF supports CSS3, allowing you to create visually appealing PDFs with precise control over their appearance.

PDF Compression: Optimize your PDFs by compressing their file size without sacrificing visual quality. This feature is particularly useful for sharing large PDFs online or via email.

Barcode and QR Code Generation: Generate barcodes or QR codes within your PDFs, making it easier to encode and share information, track inventory, or create scannable links.

PDF Annotation: Add annotations to your PDFs, including text, shapes, or drawings, to provide additional information or highlight specific content for readers.

PDF Metadata Management: Edit or retrieve metadata properties of PDF documents, such as the title, author, keywords, and more. This feature helps you keep track of important document information and improve searchability.

.NET Compatibility of IronPDF

IronPDF is compatible with a wide range of .NET platforms, including:

  • .NET Framework 4.0 and above
  • .NET Core 2.0 and above
  • .NET 6 and .NET 7
  • ASP.NET, Console, WinForms, and WPF applications

This compatibility ensures that IronPDF is a versatile solution for generating PDFs in various .NET environments.

NuGet HTML to PDF (Developer Tutorial): Figure 4

Why Choose IronPDF

IronPDF stands out among other PDF generation libraries for several reasons:

Ease of Use: IronPDF's intuitive API and comprehensive documentation make it simple for developers to start generating PDFs with minimal learning curve.

HTML, CSS, and JavaScript Support: With IronPDF, you can design your PDFs using familiar web technologies, making it easier to create complex layouts and interactive content.

Performance: IronPDF is optimized for performance, ensuring fast and efficient PDF generation, even for large documents or high-traffic applications.

Strong Community: IronPDF has an active community of developers and contributors, providing support, updates, and new features regularly.

Advanced PDF Manipulation: IronPDF offers more than just PDF generation. Its advanced features include merging, splitting, watermarking, and extraction, making it a comprehensive PDF solution for .NET developers.

Conclusion

IronPDF is a powerful and versatile NuGet PDF generator library that allows developers to create, manipulate, and manage PDFs using HTML, CSS, and JavaScript in .NET applications. With its extensive feature set and compatibility with various .NET platforms, IronPDF is a must-have tool for developers working with PDFs. By following this guide and using the provided code examples, you can quickly integrate IronPDF into your projects and begin generating professional-quality PDF documents.

IronPDF offers a free trial for those interested in trying out its powerful features. This trial period allows you to explore the full capabilities of IronPDF without any limitations. After the trial period, you can choose to purchase a license starting from $749, ensuring continued access to the robust functionality and reliable support that IronPDF provides.

< PREVIOUS
.NET 7 (How it Works for Developers Guide)
NEXT >
NuGet PDF Generator in .NET (Developer Tutorial)

Ready to get started? Version: 2024.6 just released

Start Free Trial Total downloads: 9,580,872
View Licenses >