Free C# .NET API for HTML Documents Rendering to PDF
Open Source C# .NET Library for HTML Rendering. It allows to render Office documents, HTML content and Create PDF document from HTML via C# API.
Web development has evolved significantly over the years, allowing developers to create stunning and interactive websites. HTML (Hypertext Markup Language) plays a crucial role in defining the structure and content of web pages. Among these libraries, HTML Renderer stands out as a versatile tool for rendering HTML content within applications. One of the standout features of HTML Renderer is its cross-platform compatibility and it works effectively on different operating systems, including Windows, macOS, and Linux, making it an ideal choice for multi-platform applications.
HTML Renderer is a powerful library that enables software developers to load and convert HTML markup into visually appealing representations within their applications. There are several important features part of the library such as rendering of Office documents, rendering HTML content generated by rich web editors, creating images from HTML code snippets, creating PDF documents from HTML code snippets, text selection & copy-paste support, separating CSS from HTML, and many more. Moreover, the library provides a way to programmatically render HTML content, which can be customized and integrated seamlessly with various application frameworks.
The HTML Renderer library provides an extensible architecture that allows developers to customize and extend its functionality according to their specific needs. By leveraging the HTML Renderer library, developers can save time by avoiding the need to build complex rendering engines from scratch. The library handles the intricacies of HTML rendering, allowing developers to focus on other critical aspects of their applications. With the HTML Renderer library, developers can reuse their existing HTML and CSS knowledge, as the library supports standard HTML tags and CSS styles. Whether you're building desktop applications, web applications, or any other software that requires HTML rendering capabilities, the HTML Renderer library proves to be an invaluable asset.
At A Glance
An overview of HTML Renderer features.
- CreatE PDF from HTML
- create images from HTML
- Render Office documents
- Create Images from HTML
- Open HTML
- Read HTML
- Parse HTML
- HTML rendering
- HTML Viewer
- HTML to PDF
- Extract TOC
- Extract plain text
HTML Renderer supports PDF file format as well as industry-standard formats for export.
HTML Renderer includes .NET Core >= 1.0 & .NET Framework >= 4.6
- .NET Framework >= 4.6
- .NET Standard >= 1.3
Getting Started with HTML Renderer
The recommended way to install HTML Renderer is using NuGet. Please use the following command a smooth installation.
Install HTML Renderer via NuGet
You can also install it manually; download the latest release files directly from GitHub repository.
Create Image from HTML via C# Library
Generating images from HTML using the HTML Renderer library can be a useful feature in applications where visual representations of HTML content are required. To achieve the goal first software developer needs to load and render the HTML content and once the HTML content is loaded, developers can easily render it to an image. Once rendering to an image process is completed, after that you can save it to a file or perform additional operations, such as resizing, cropping, or applying filters. Please, make sure that the HTML content you provide is well-formed and includes all necessary CSS styles and resources for proper rendering in the image. The following example shows how to generate an image from HTML using the HTML Renderer library.
How to Generate an Image from HTML using C# Library?
using HtmlRenderer; // ... var htmlContainer = new HtmlContainer(); // Set any additional options or properties htmlContainer.Width = 800; htmlContainer.Height = 600; htmlContainer.BackColor = Color.White; htmlContainer.AvoidAsyncImagesLoading = true; //Load and render the HTML content: string htmlContent = "
Hello, Image!"; htmlContainer.SetHtml(htmlContent); Bitmap image = htmlContainer.Draw(); // Save or manipulate the resulting image image.Save("output.png", ImageFormat.Png);
HTML to PDF Conversion via C# API
The open source HTML Renderer library provides a straightforward and efficient way to accomplish HTML to PDF conversion inside C# applications. The library needs just a couple of lines C# code for converting HTML content to PDF documents. This functionality is particularly useful for generating printable versions of web pages or creating reports within applications. The following example demonstrates how to convert HTML to PDF inside .NET applications.
Convert HTML to PDF inside .NET applications
using HtmlRenderer.PdfSharp; // ... var converter = new HtmlToPdfConverter(); converter.PageOrientation = PdfSharp.PageOrientation.Portrait; converter.PageMargins = new PdfSharp.PageSize(50); // convert HTML to PDF string htmlContent = "
Hello, PDF!"; PdfSharp.Pdf.PdfDocument pdfDocument = converter.ConvertHtml(htmlContent); // Save the resulting PDF document: pdfDocument.Save("output.pdf");