Convert HTML To PDF Using Telerik

If you are using Telerik and would like to convert HTML to PDF with the Document Processing Library, this code provided by Telerik's support Team will help you.

Here is the  "magic":

var htmlDocument = new Telerik.Windows.Documents.Flow.FormatProviders.Html.HtmlFormatProvider();  
var doc = htmlDocument.Import(File.ReadAllText(@"..\..\test.html"));  
  
var pdf = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();  
using (Stream output = File.OpenWrite(@"..\..\result.pdf"))  
{  
    pdf.Export(doc, output);  
}

The Telerik.Windows.Documents.The flow package is part of the WordsProcessing library. Processing documents in HTML, DOCX, RTF, and TXT formats.

It is available in other packs, such as:

  1. Telerik UI for ASP.NET (AJAX and .NET Core)
  2. Kendo UI
  3. Telerik UI for WPF
  4. Telerik UI for WinUI
  5. Telerik UI for WinForms
  6. Telerik UI for Xamarin
  7. Telerik UI for Blazor
  8. Telerik UI for .NET MAUI

Word processing libraries are UI-agnostic and can be used without the need to purchase additional licenses.

I am Progress Telerik Champion and if you have questions about Telerik I am available to help you, please contact me on my LinkedIn.

I hope this helps me or someone else in the future.

Happy coding.