Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
In this comparison video, we explore the differences between Iron PDF and Select PDF for HTML to PDF conversion using the .NET framework. The process begins with setting up a project in .NET 5 and installing the necessary libraries via the NuGet package manager. When testing Select PDF, the conversion resulted in missing elements like logos and images, as well as incomplete CSS styling, leading to a subpar PDF output. Iron PDF, on the other hand, produced an output that closely mirrored the original website, preserving images, styles, and responsiveness effectively. It also demonstrated superior CSS application, ensuring the PDF looked identical to the website displayed in a browser. Overall, Iron PDF proved to be a more reliable and comprehensive tool for developers needing accurate HTML to PDF conversions, supporting the latest .NET and .NET Core frameworks while complying with HTML5 and CSS3 standards. This comparison highlights Iron PDF's capabilities and why it's a preferred choice in the market.
Further Reading: A Comparison of IronPDF vs SelectPDF
Below is a sample code snippet demonstrating how to convert HTML to PDF using Iron PDF in a .NET Core application. Comments have been added for clarity.
// Import necessary namespaces for using IronPDF
using IronPdf;
class HtmlToPdfExample
{
static void Main(string[] args)
{
try
{
// Create an instance of the HtmlToPdf class
HtmlToPdf Renderer = new HtmlToPdf();
// Define the URL or HTML content you want to convert
// Here we use a URL as an example
string htmlUrl = "https://www.example.com";
// Convert the HTML at the specified URL to PDF
PdfDocument pdfDocument = Renderer.RenderUrlAsPdf(htmlUrl);
// Specify the path where the PDF will be saved
string outputPath = @"C:\path\to\output\document.pdf";
// Save the PDF document to the specified file path
pdfDocument.SaveAs(outputPath);
Console.WriteLine("PDF conversion successful. File saved at: " + outputPath);
}
catch (Exception ex)
{
// Catch and display any errors that occur during the conversion process
Console.WriteLine("An error occurred: " + ex.Message);
}
}
}
// Import necessary namespaces for using IronPDF
using IronPdf;
class HtmlToPdfExample
{
static void Main(string[] args)
{
try
{
// Create an instance of the HtmlToPdf class
HtmlToPdf Renderer = new HtmlToPdf();
// Define the URL or HTML content you want to convert
// Here we use a URL as an example
string htmlUrl = "https://www.example.com";
// Convert the HTML at the specified URL to PDF
PdfDocument pdfDocument = Renderer.RenderUrlAsPdf(htmlUrl);
// Specify the path where the PDF will be saved
string outputPath = @"C:\path\to\output\document.pdf";
// Save the PDF document to the specified file path
pdfDocument.SaveAs(outputPath);
Console.WriteLine("PDF conversion successful. File saved at: " + outputPath);
}
catch (Exception ex)
{
// Catch and display any errors that occur during the conversion process
Console.WriteLine("An error occurred: " + ex.Message);
}
}
}
' Import necessary namespaces for using IronPDF
Imports IronPdf
Friend Class HtmlToPdfExample
Shared Sub Main(ByVal args() As String)
Try
' Create an instance of the HtmlToPdf class
Dim Renderer As New HtmlToPdf()
' Define the URL or HTML content you want to convert
' Here we use a URL as an example
Dim htmlUrl As String = "https://www.example.com"
' Convert the HTML at the specified URL to PDF
Dim pdfDocument As PdfDocument = Renderer.RenderUrlAsPdf(htmlUrl)
' Specify the path where the PDF will be saved
Dim outputPath As String = "C:\path\to\output\document.pdf"
' Save the PDF document to the specified file path
pdfDocument.SaveAs(outputPath)
Console.WriteLine("PDF conversion successful. File saved at: " & outputPath)
Catch ex As Exception
' Catch and display any errors that occur during the conversion process
Console.WriteLine("An error occurred: " & ex.Message)
End Try
End Sub
End Class
HtmlToPdf
class is used to create a renderer object that will perform the conversion.Ensure that you have the Iron PDF library installed in your project to execute this code successfully.