Exploring Alternatives to DinkToPDF for HTML to PDF Conversion

In today's tutorial, we explore a comparison between two popular C# libraries for converting HTML to PDF: Iron PDF and Dink to PDF. We begin by ensuring both libraries are installed using the NuGet package manager. Iron PDF utilizes a Chrome PDF renderer instance to convert HTML content into high-quality PDF documents, easily handling both HTML strings and URLs. In contrast, Dink to PDF involves defining global and object settings for PDF creation, serving as a wrapper for the WKHTML to PDF library. While both libraries are effective, Iron PDF provides a simpler, more pixel-perfect solution with dedicated features for PDF handling. Dink to PDF's strength lies in its configuration flexibility. Ultimately, the choice depends on your specific application needs. Experiment with both to determine which suits your project best. For further exploration, check out the software link provided to download and test these libraries yourself.

Here's a basic example of how to use each library:

Iron PDF Example

// Ensure you have installed the IronPDF NuGet package before running this example.

using IronPdf;

class Program
{
    static void Main()
    {
        // Create a PDF Renderer using IronPDF
        var Renderer = new HtmlToPdf();

        // Render an HTML string as a PDF document
        var PDF = Renderer.RenderHtmlAsPdf("<h1>Hello, World!</h1>");

        // Save the PDF document to the file system
        PDF.SaveAs("HelloWorld.pdf");

        // Open the PDF document in the default viewer
        System.Diagnostics.Process.Start("HelloWorld.pdf");
    }
}
// Ensure you have installed the IronPDF NuGet package before running this example.

using IronPdf;

class Program
{
    static void Main()
    {
        // Create a PDF Renderer using IronPDF
        var Renderer = new HtmlToPdf();

        // Render an HTML string as a PDF document
        var PDF = Renderer.RenderHtmlAsPdf("<h1>Hello, World!</h1>");

        // Save the PDF document to the file system
        PDF.SaveAs("HelloWorld.pdf");

        // Open the PDF document in the default viewer
        System.Diagnostics.Process.Start("HelloWorld.pdf");
    }
}
' Ensure you have installed the IronPDF NuGet package before running this example.

Imports IronPdf

Friend Class Program
	Shared Sub Main()
		' Create a PDF Renderer using IronPDF
		Dim Renderer = New HtmlToPdf()

		' Render an HTML string as a PDF document
		Dim PDF = Renderer.RenderHtmlAsPdf("<h1>Hello, World!</h1>")

		' Save the PDF document to the file system
		PDF.SaveAs("HelloWorld.pdf")

		' Open the PDF document in the default viewer
		System.Diagnostics.Process.Start("HelloWorld.pdf")
	End Sub
End Class
$vbLabelText   $csharpLabel

Dink to PDF Example

// Ensure you have installed the DinkToPdf and DinkToPdf.Native.System32 NuGet packages before running this example.

using System.Diagnostics;
using DinkToPdf;
using DinkToPdf.Contracts;

class Program
{
    static void Main()
    {
        // Initialize a converter
        var converter = new BasicConverter(new PdfTools());

        // Define global settings for PDF conversion
        var globalSettings = new GlobalSettings
        {
            ColorMode = ColorMode.Color,
            Orientation = Orientation.Portrait,
            PaperSize = PaperKind.A4,
            Margins = new MarginSettings { Top = 10 }
        };

        // Define object settings to convert specific html
        var objectSettings = new ObjectSettings
        {
            PagesCount = true,
            HtmlContent = "<h1>Hello, World!</h1>",
            WebSettings = { DefaultEncoding = "utf-8" },
            HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true }
        };

        // Create the PDF document with specified settings
        var pdfDocument = new HtmlToPdfDocument()
        {
            GlobalSettings = globalSettings,
            Objects = { objectSettings }
        };

        // Convert the document and save to the file system
        converter.Convert(pdfDocument, "HelloWorld.pdf");

        // Open the PDF document in the default viewer
        Process.Start("HelloWorld.pdf");
    }
}
// Ensure you have installed the DinkToPdf and DinkToPdf.Native.System32 NuGet packages before running this example.

using System.Diagnostics;
using DinkToPdf;
using DinkToPdf.Contracts;

class Program
{
    static void Main()
    {
        // Initialize a converter
        var converter = new BasicConverter(new PdfTools());

        // Define global settings for PDF conversion
        var globalSettings = new GlobalSettings
        {
            ColorMode = ColorMode.Color,
            Orientation = Orientation.Portrait,
            PaperSize = PaperKind.A4,
            Margins = new MarginSettings { Top = 10 }
        };

        // Define object settings to convert specific html
        var objectSettings = new ObjectSettings
        {
            PagesCount = true,
            HtmlContent = "<h1>Hello, World!</h1>",
            WebSettings = { DefaultEncoding = "utf-8" },
            HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true }
        };

        // Create the PDF document with specified settings
        var pdfDocument = new HtmlToPdfDocument()
        {
            GlobalSettings = globalSettings,
            Objects = { objectSettings }
        };

        // Convert the document and save to the file system
        converter.Convert(pdfDocument, "HelloWorld.pdf");

        // Open the PDF document in the default viewer
        Process.Start("HelloWorld.pdf");
    }
}
' Ensure you have installed the DinkToPdf and DinkToPdf.Native.System32 NuGet packages before running this example.

Imports System.Diagnostics
Imports DinkToPdf
Imports DinkToPdf.Contracts

Friend Class Program
	Shared Sub Main()
		' Initialize a converter
		Dim converter = New BasicConverter(New PdfTools())

		' Define global settings for PDF conversion
		Dim globalSettings As New GlobalSettings With {
			.ColorMode = ColorMode.Color,
			.Orientation = Orientation.Portrait,
			.PaperSize = PaperKind.A4,
			.Margins = New MarginSettings With {.Top = 10}
		}

		' Define object settings to convert specific html
		Dim objectSettings As New ObjectSettings With {
			.PagesCount = True,
			.HtmlContent = "<h1>Hello, World!</h1>",
			.WebSettings = { DefaultEncoding = "utf-8" },
			.HeaderSettings = {
				FontName = "Arial",
				FontSize = 9,
				Right = "Page [page] of [toPage]",
				Line = True
			}
		}

		' Create the PDF document with specified settings
		Dim pdfDocument = New HtmlToPdfDocument() With {
			.GlobalSettings = globalSettings,
			.Objects = { objectSettings }
		}

		' Convert the document and save to the file system
		converter.Convert(pdfDocument, "HelloWorld.pdf")

		' Open the PDF document in the default viewer
		Process.Start("HelloWorld.pdf")
	End Sub
End Class
$vbLabelText   $csharpLabel

Further Reading: Exploring Alternatives to DinkToPDF for HTML to PDF Conversion

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of all products is growing daily, as he finds new ways to support customers. He enjoys how collaborative life is at Iron Software, with team members from across the company bringing their varied experience to contribute to effective, innovative solutions. When Chipego is away from his desk, he can often be found enjoying a good book or playing football.
< PREVIOUS
A comparison of HTML to PDF in IronPDF vs iText7
NEXT >
How to Convert HTML to PDF with C# in .NET 8