C# Create PDF (Code Example Tutorial)

This article will teach you how to produce PDF documents from a web page in the C#.NET programming language using IronPDF.

IronPDF is a fully-featured PDF library for .NET and Java. It is one of several third-party libraries available that work efficiently in creating, editing, and processing PDF documents, as well as in outputting editable PDF files from content of other file types (HTML, PNG, RTF, etc). Find out more about IronPDF and similar PDF libraries from our growing catalog of comparison articles.


As HTML is a markup language, it can be difficult to convert the contents of HTML to a PDF without the HTML tags. We'll be working with IronPDF for this tutorial to do just that, create PDF in C# from HTML, because of its ease of use and additional features like using JavaScript, CSS, and images.

In this article, we are going to cover in detail, HTML to PDF. conversion in C#, provided by IronPDF.

When I need to create, read, generate or manipulate pdf files, I always prefer IronPdf, as it has the best library, is easy to use, and provides great features.


1. Create a New Project in Visual Studio

Open the Visual Studio software and go to the File menu. Select "new project" and then select "console application". In this article, we are going to use a console application to generate PDF documents.

Enter the project name and select the path in the appropriate text box. Then, click the next button.

Select the required .NET framework then, click the create button, as shown below:

The Visual Studio project will now generate the structure for the selected application, and if you have selected the console, Windows, and web application, it will open the program.cs file where you can enter the code and build/run the application.

Now we can add the library and test the program.

Using the Visual Studio NuGet Package Manager

The Visual Studio software provides the NuGet Package Manager option to install the package directly to the solution. The below screenshot shows how to open the NuGet Package Manager.

Don't worry about license key, IronPDF is free for development.

It provides the search box to show the list of available package libraries from the NuGet website. In the package manager, we need to search for the keyword "IronPDF", as shown in the below screenshot:

From the above image, we will get the list of the related NuGet packages search list. We need to select the IronPDF option and install the package for the solution.

Using the Visual Studio Command-Line

In the Visual Studio menu, Go to Tools-> NuGet Package manager -> Package manager console

Enter the following line in the package manager console tab: Install-Package IronPDF

Now the package will download/install to the current project and be ready to use.

2. Create a PDF from HTML using RenderHtmlToPdf()

After the IronPDF library is installed we can effortlessly create a PDF file and PDF Page by using just a few lines of code. Now we will help you create your first pdf document in C#. Copy the below code and paste it into your Visual Studio and Run the program.

var pdf = new ChromePdfRenderer();
PdfDocument doc = pdf.RenderHtmlAsPdf("<h1>This is a heading</h1>");
mypdf.SaveAs("FirstPDFDocument.pdf");
var pdf = new ChromePdfRenderer();
PdfDocument doc = pdf.RenderHtmlAsPdf("<h1>This is a heading</h1>");
mypdf.SaveAs("FirstPDFDocument.pdf");
Dim pdf = New ChromePdfRenderer()
Dim doc As PdfDocument = pdf.RenderHtmlAsPdf("<h1>This is a heading</h1>")
mypdf.SaveAs("FirstPDFDocument.pdf")
VB   C#

After execution of your C# project there will be a file mane "FirstPDFDocument.pdf" in the bin folder of your project, double click on the said file, and the PDF file will open in the browser tab.

Creating pdf files in C# or creating pdf files converting HTML to PDF is just a few lines of code using IronPDF.

3. Create PDF Document from URL

Creating a pdf file in C# using a URL is just as easy as the above example with just these three lines of code, following code will demonstrate how to create pdf files from a URL.

using IronPdf;
var Renderer = new IronPdf.ChromePdfRenderer();
// Create a PDF from a URL or local file path
using var pdf = Renderer.RenderUrlAsPdf("https://www.amazon.com/?tag=hp2-brobookmark-us-20");
// Export to a file or Stream
pdf.SaveAs("url.pdf");
using IronPdf;
var Renderer = new IronPdf.ChromePdfRenderer();
// Create a PDF from a URL or local file path
using var pdf = Renderer.RenderUrlAsPdf("https://www.amazon.com/?tag=hp2-brobookmark-us-20");
// Export to a file or Stream
pdf.SaveAs("url.pdf");
Imports IronPdf
Private Renderer = New IronPdf.ChromePdfRenderer()
' Create a PDF from a URL or local file path
Private pdf = Renderer.RenderUrlAsPdf("https://www.amazon.com/?tag=hp2-brobookmark-us-20")
' Export to a file or Stream
pdf.SaveAs("url.pdf")
VB   C#

Here is the output of the above code.

Other examples of converting popular complex sites to PDF.

4. Render ASP.NET and MVC to PDF

It is possible to serve an existing HTML file or string, an existing PDF document, as well as a PDF in ASP.NET MVC. In order to serve existing PDF files, HTML files, or strings, as well as serving a PDF in ASP.NET MVC, we can use the C# PDF Library from IronPDF and then access it via DLL ZIP file or through the NuGet page.

To serve a PDF document in ASP.NET MVC requires generating a FileResult method. With IronPDF you can use MVC to return a PDF file.

 var Renderer = new IronPdf.ChromePdfRenderer();
 using var PDF = Renderer.RenderHTMLFileAsPdf("Project/MyHtmlDocument.html");
// or to convert an HTML string
//var PDF = Renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>");
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition","attachment;filename=\"FileName.pdf\"");
// edit this line to display ion browser and change the file name
Response.BinaryWrite( PDF.BinaryData );
Response.Flush();
Response.End();
 var Renderer = new IronPdf.ChromePdfRenderer();
 using var PDF = Renderer.RenderHTMLFileAsPdf("Project/MyHtmlDocument.html");
// or to convert an HTML string
//var PDF = Renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>");
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition","attachment;filename=\"FileName.pdf\"");
// edit this line to display ion browser and change the file name
Response.BinaryWrite( PDF.BinaryData );
Response.Flush();
Response.End();
Dim Renderer = New IronPdf.ChromePdfRenderer()
 Dim PDF = Renderer.RenderHTMLFileAsPdf("Project/MyHtmlDocument.html")
' or to convert an HTML string
'var PDF = Renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>");
Response.Clear()
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Disposition","attachment;filename=""FileName.pdf""")
' edit this line to display ion browser and change the file name
Response.BinaryWrite(PDF.BinaryData)
Response.Flush()
Response.End()
VB   C#

5. Render Razor Views To PDF

The following method makes it easy to render a Razor view to a string. IronPDF’s HTML to PDF functionality can be used to render that Razor view as a string. Don’t forget to set the optional BaseURI parameter of the IronPdf.ChromePdfRenderer.RenderHtmlAsPdf Method to load relative assets, CSS, JavaScript and images. Here is an example:

public string RenderRazorViewToString(string viewName, object model)
{
ViewData.Model = model;
    using (var sw = new StringWriter())
    {
        var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext,
        viewName);
        var viewContext = new ViewContext(ControllerContext, viewResult.View,
        ViewData, TempData, sw);
        viewResult.View.Render(viewContext, sw);
        viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
        return sw.GetStringBuilder().ToString();
    }
}
public string RenderRazorViewToString(string viewName, object model)
{
ViewData.Model = model;
    using (var sw = new StringWriter())
    {
        var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext,
        viewName);
        var viewContext = new ViewContext(ControllerContext, viewResult.View,
        ViewData, TempData, sw);
        viewResult.View.Render(viewContext, sw);
        viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
        return sw.GetStringBuilder().ToString();
    }
}
Public Function RenderRazorViewToString(ByVal viewName As String, ByVal model As Object) As String
ViewData.Model = model
	Using sw = New StringWriter()
		Dim viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName)
		Dim viewContext As New ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw)
		viewResult.View.Render(viewContext, sw)
		viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View)
		Return sw.GetStringBuilder().ToString()
	End Using
End Function
VB   C#

Please read the .NET MVC PDF documentation page to learn how to render an MVC view as a binary PDF file.

6. Convert XML to PDF

C# XML to PDF directly can be a complex challenge. We've found that to convert XML to PDF in C# it is best to start with XSLT. XML and may be rendered to PDF via HTML(5) using XLST transformations.

These documents define how XML from a given schema may be converted to an accurate HTML representation and are a well-established standard.

The resultant HTML string or file may then be rendered as a PDF using the .NET PDF Generator:

Here is an example:

XslCompiledTransform transform = new XslCompiledTransform();
using(XmlReader reader = XmlReader.Create(new StringReader(XSLT))) {
    transform.Load(reader);
}
StringWriter results = new StringWriter();
using(XmlReader reader = XmlReader.Create(new StringReader(XML))) {
    transform.Transform(reader, null, results);
}
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
// options, headers and footers may be set there
// Render our XML as a PDF via XSLT
Renderer.RenderHtmlAsPdf(results.ToString()).SaveAs("Final.pdf");
XslCompiledTransform transform = new XslCompiledTransform();
using(XmlReader reader = XmlReader.Create(new StringReader(XSLT))) {
    transform.Load(reader);
}
StringWriter results = new StringWriter();
using(XmlReader reader = XmlReader.Create(new StringReader(XML))) {
    transform.Transform(reader, null, results);
}
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
// options, headers and footers may be set there
// Render our XML as a PDF via XSLT
Renderer.RenderHtmlAsPdf(results.ToString()).SaveAs("Final.pdf");
Dim transform As New XslCompiledTransform()
Using reader As XmlReader = XmlReader.Create(New StringReader(XSLT))
	transform.Load(reader)
End Using
Dim results As New StringWriter()
Using reader As XmlReader = XmlReader.Create(New StringReader(XML))
	transform.Transform(reader, Nothing, results)
End Using
Dim Renderer As New IronPdf.ChromePdfRenderer()
' options, headers and footers may be set there
' Render our XML as a PDF via XSLT
Renderer.RenderHtmlAsPdf(results.ToString()).SaveAs("Final.pdf")
VB   C#

7. Generate PDF Reports

IronPDF can be used as a PDF reader C# and help visualize and export SSRS reports to PDF in ASP.NET CSharp. IronPDF can be used to render snapshots of data as "reports" in the PDF File Format. It also works as a PDF C# parser. The basic methodology is to first generate the report as an HTML document - and then to render the HTML as a PDF using IronPDF.

To style an XML report, the XML may be parsed and then the HTML is generated with the data. These reports may be generated as HTML which may then be customized and converted to PDF format using IronPDF. The easiest way to serve HTML content in ASP.NET is to use the IronPdf.AspxToPdf class on the Form_Load event of an ASP.NET WebForms.

Here is an example:

IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
// add a header to very page easily
Renderer.RenderingOptions.FirstPageNumber = 1;
Renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
Renderer.RenderingOptions.TextHeader.CenterText = "{url}";
Renderer.RenderingOptions.TextHeader.FontFamily = "Helvetica,Arial";
Renderer.RenderingOptions.TextHeader.FontSize = 12;
// add a footer too
Renderer.RenderingOptions.TextFooter.DrawDividerLine = true;
Renderer.RenderingOptions.TextFooter.FontFamily = "Arial";
Renderer.RenderingOptions.TextFooter.FontSize = 10;
Renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}";
Renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}";
Renderer.RenderHtmlFileAsPdf("Report.html").SaveAs("Report.pdf");
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
// add a header to very page easily
Renderer.RenderingOptions.FirstPageNumber = 1;
Renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
Renderer.RenderingOptions.TextHeader.CenterText = "{url}";
Renderer.RenderingOptions.TextHeader.FontFamily = "Helvetica,Arial";
Renderer.RenderingOptions.TextHeader.FontSize = 12;
// add a footer too
Renderer.RenderingOptions.TextFooter.DrawDividerLine = true;
Renderer.RenderingOptions.TextFooter.FontFamily = "Arial";
Renderer.RenderingOptions.TextFooter.FontSize = 10;
Renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}";
Renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}";
Renderer.RenderHtmlFileAsPdf("Report.html").SaveAs("Report.pdf");
Dim Renderer As New IronPdf.ChromePdfRenderer()
' add a header to very page easily
Renderer.RenderingOptions.FirstPageNumber = 1
Renderer.RenderingOptions.TextHeader.DrawDividerLine = True
Renderer.RenderingOptions.TextHeader.CenterText = "{url}"
Renderer.RenderingOptions.TextHeader.FontFamily = "Helvetica,Arial"
Renderer.RenderingOptions.TextHeader.FontSize = 12
' add a footer too
Renderer.RenderingOptions.TextFooter.DrawDividerLine = True
Renderer.RenderingOptions.TextFooter.FontFamily = "Arial"
Renderer.RenderingOptions.TextFooter.FontSize = 10
Renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}"
Renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}"
Renderer.RenderHtmlFileAsPdf("Report.html").SaveAs("Report.pdf")
VB   C#

8. Work with PDF images and CSS

The answer, in this case of HTML String to PDF, is that we should set a BaseUri when working with assets. All assets such as CSS, JavaScript files, and images will be loaded relative to that base URL.

The BaseURL may be a web URL starting with “http” to load remote assets, or a local file path to access assets on your disk.

Another trick is to use the IronPdf.Imaging.ImageUtilities.ImageToDataUri method to convert any System.Drawing.Image or Bitmap object into an HTML string which can be embedded in HTML without saving to disk. Here is an example:

using var PDF = Renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>",@"C:\site\assets\");
PDF.SaveAs("html-with-assets.pdf");
var Renderer = new IronPdf.ChromePdfRenderer();
using var AdvancedPDF = Renderer.RenderHTMLFileAsPdf("C:\\Assets\\TestInvoice1.html");
AdvancedPDF.SaveAs("Invoice.pdf");
using var PDF = Renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>",@"C:\site\assets\");
PDF.SaveAs("html-with-assets.pdf");
var Renderer = new IronPdf.ChromePdfRenderer();
using var AdvancedPDF = Renderer.RenderHTMLFileAsPdf("C:\\Assets\\TestInvoice1.html");
AdvancedPDF.SaveAs("Invoice.pdf");
Dim PDF = Renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>","C:\site\assets\")
PDF.SaveAs("html-with-assets.pdf")
Dim Renderer = New IronPdf.ChromePdfRenderer()
Dim AdvancedPDF = Renderer.RenderHTMLFileAsPdf("C:\Assets\TestInvoice1.html")
AdvancedPDF.SaveAs("Invoice.pdf")
VB   C#

9. Convert ASPX Files to PDF

First, let's access the 'free for development' C# Library for converting ASPX files to PDF. You can download it directly or access it via NuGet. Install as usual into your Visual Studio project. Now that you have IronPDF, you'll see that it has the functionality for HTML conversion as well as ASPX to PDF generation.

We can convert ASPX pages to either our own developed webpage or any website which is developed on ASP.NET. Here is an example:

using System;
using System.Web.UI;
using IronPdf;

namespace aspxtopdf
{
    public partial class SiteMaster : MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            AspxToPdf.RenderThisPageAsPdf();
        }
    }
}
using System;
using System.Web.UI;
using IronPdf;

namespace aspxtopdf
{
    public partial class SiteMaster : MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            AspxToPdf.RenderThisPageAsPdf();
        }
    }
}
Imports System
Imports System.Web.UI
Imports IronPdf

Namespace aspxtopdf
	Partial Public Class SiteMaster
		Inherits MasterPage

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
			AspxToPdf.RenderThisPageAsPdf()
		End Sub
	End Class
End Namespace
VB   C#
CSharp Create PDF

10. View HTML to PDF Example File

IronPDF converts HTML to PDF documents programmatically. It can be installed directly from IronPdf or via NuGet.

If you don't know about Installing IronPdf NuGet Packages, you can visit my previous article.

The package name is IronPDF. After IronPDF is installed and referenced in your project you can start using it right away by typing a couple of strings. Here is an example:

var uri = new Uri("https://www.c-sharpcorner.com/article/how-to-create-pdf-file-in-c-sharp-using-ironpdf/");
// turn page into pdf
var pdf = ChromePdfRenderer.StaticRenderUrlAsPdf(uri);
// save resulting pdf into file
pdf.SaveAs(Path.Combine(Directory.GetCurrentDirectory(), "UrlToPdf.Pdf"));
var uri = new Uri("https://www.c-sharpcorner.com/article/how-to-create-pdf-file-in-c-sharp-using-ironpdf/");
// turn page into pdf
var pdf = ChromePdfRenderer.StaticRenderUrlAsPdf(uri);
// save resulting pdf into file
pdf.SaveAs(Path.Combine(Directory.GetCurrentDirectory(), "UrlToPdf.Pdf"));
Dim uri As New Uri("https://www.c-sharpcorner.com/article/how-to-create-pdf-file-in-c-sharp-using-ironpdf/")
' turn page into pdf
Dim pdf = ChromePdfRenderer.StaticRenderUrlAsPdf(uri)
' save resulting pdf into file
pdf.SaveAs(Path.Combine(Directory.GetCurrentDirectory(), "UrlToPdf.Pdf"))
VB   C#

Pdf file is created inside the Debug folder of our App. Here is the output:

11. Generate PDF File in C# .NET

With an extensive C# library, we can convert ASP.NET to PDF and HTML to PDF and have full control over reading, editing, and manipulating documents. Using IronPDF, we can convert an ASP.NET page to a PDF file in C# in just a single line of code.

To get access to the full software library of C# PDF functionality, you can download IronPDF and use it free for development in your project. Either install from a ZIP DLL Download or use the package via NuGet install. You can even convert an ASP .NET to PDF in just one line of code.

Here is an example:

using System;
using System.Web.UI;
using IronPdf;
namespace aspxtopdf
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            AspxToPdf.RenderThisPageAsPdf();
        }
    }
}
using System;
using System.Web.UI;
using IronPdf;
namespace aspxtopdf
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            AspxToPdf.RenderThisPageAsPdf();
        }
    }
}
Imports System
Imports System.Web.UI
Imports IronPdf
Namespace aspxtopdf
	Partial Public Class _Default
		Inherits Page

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

		End Sub
		Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
			AspxToPdf.RenderThisPageAsPdf()
		End Sub
	End Class
End Namespace
VB   C#
CSharp Create PDF

12. Generate PDF Document

Install the IronPDF C# HTML to PDF library. Access the software by direct file download or through the latest NuGet Package install to load into Visual Studio and your project. The IronPDF library simplifies PDF tasks into easy-to-use and understandable .NET methods.

Firstly, Speed! Not only does IronPDF generate PDF files for .NET quicker, but it also increases developer productivity because of the easy naming convention employed for methods in the IronPDF .NET PDF library.

Secondly, ease of use! As mentioned previously, the IronPDF .NET PDF library is very easy to work with. It is easy to identify method names and understand their purpose. .NET developers will not struggle to get generate PDF in .NET with this pdf library in either VB.NET or C#.

Here is a very quick example of how to generate a PDF from an HTML input string:

/**
PDF from HTML String
anchor-generate-pdf-from-html-string
**/
private void HTMLString()
        {
            // Render any HTML fragment or document to HTML
            var Renderer = new IronPdf.ChromePdfRenderer();
            using var PDF = Renderer.RenderHtmlAsPdf("<h1>Hello IronPDF</h1>");
            var OutputPath = "ChromePdfRenderer.pdf";
            PDF.SaveAs(OutputPath);
        }
/**
PDF from HTML String
anchor-generate-pdf-from-html-string
**/
private void HTMLString()
        {
            // Render any HTML fragment or document to HTML
            var Renderer = new IronPdf.ChromePdfRenderer();
            using var PDF = Renderer.RenderHtmlAsPdf("<h1>Hello IronPDF</h1>");
            var OutputPath = "ChromePdfRenderer.pdf";
            PDF.SaveAs(OutputPath);
        }
'''
'''PDF from HTML String
'''anchor-generate-pdf-from-html-string
'''*
Private Sub HTMLString()
			' Render any HTML fragment or document to HTML
			Dim Renderer = New IronPdf.ChromePdfRenderer()
			Dim PDF = Renderer.RenderHtmlAsPdf("<h1>Hello IronPDF</h1>")
			Dim OutputPath = "ChromePdfRenderer.pdf"
			PDF.SaveAs(OutputPath)
End Sub
VB   C#

The following code makes use of IronPDF to generate a PDF directly from an ASPX file:

/**
PDF from ASPX
anchor-generate-pdf-from-aspx
**/
protected void Page_Load(object sender, EventArgs e)
        {
            IronPdf.AspxToPdf.RenderThisPageAsPdf();
        }
/**
PDF from ASPX
anchor-generate-pdf-from-aspx
**/
protected void Page_Load(object sender, EventArgs e)
        {
            IronPdf.AspxToPdf.RenderThisPageAsPdf();
        }
'''
'''PDF from ASPX
'''anchor-generate-pdf-from-aspx
'''*
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
			IronPdf.AspxToPdf.RenderThisPageAsPdf()
End Sub
VB   C#

IronPDF supports JavaScript quite nicely via the Chromium rendering engine. One stipulation though, you may have to add a delay to a page render to allow JavaScript time to execute whilst generating PDFs.

13. PDF Library For .NET

Using IronPDF, we're able to create and edit PDF features in a simple manner according to our application requirements. IronPDF provides a suite of functionality with its C# .NET PDF Library and provides it free for developers to experiment and optimize their projects before deployment. The two main ways of accessing the library are to either:

  1. Download and unpack the DLL file
  2. Navigate NuGet and install the package via Visual Studio.

In the code below, we have used a C# Form demonstrating simply how to create a PDF with C#

using IronPdf;
using System.Windows.Forms;

namespace readpdf
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            //Used ChromePdfRenderer Convert Class
            var HtmlLine = new ChromePdfRenderer();
            //Getting Text from TextBox
            string text = textBox1.Text;
            //Here we are rendering or converting htmlaspdf.
            HtmlLine.RenderHtmlAsPdf("<h1>"+text+"</h1>").SaveAs("custom.pdf");
            //Confirmation
            MessageBox.Show("Done !");
        }
    }
}
using IronPdf;
using System.Windows.Forms;

namespace readpdf
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            //Used ChromePdfRenderer Convert Class
            var HtmlLine = new ChromePdfRenderer();
            //Getting Text from TextBox
            string text = textBox1.Text;
            //Here we are rendering or converting htmlaspdf.
            HtmlLine.RenderHtmlAsPdf("<h1>"+text+"</h1>").SaveAs("custom.pdf");
            //Confirmation
            MessageBox.Show("Done !");
        }
    }
}
Imports IronPdf
Imports System.Windows.Forms

Namespace readpdf
	Partial Public Class Form1
		Inherits Form

		Public Sub New()
			InitializeComponent()
		End Sub
		Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			'Used ChromePdfRenderer Convert Class
			Dim HtmlLine = New ChromePdfRenderer()
			'Getting Text from TextBox
'INSTANT VB NOTE: The variable text was renamed since Visual Basic does not handle local variables named the same as class members well:
			Dim text_Conflict As String = textBox1.Text
			'Here we are rendering or converting htmlaspdf.
			HtmlLine.RenderHtmlAsPdf("<h1>" & text_Conflict &"</h1>").SaveAs("custom.pdf")
			'Confirmation
			MessageBox.Show("Done !")
		End Sub
	End Class
End Namespace
VB   C#

C# Form:

CSharp Create PDF

14. Chrome PDF Rendering Engine

The Iron Software engineering team is proud to release a game-changing upgrade to IronPDF in 2021, now featuring “Chrome Identical” PDF rendering.

First you must install IronPDF into your project from the NuGet Package Manager named IronPdf. Changing to the new renderer at a global level is simple. This approach updates all usages of your existing ChromePdfRenderer and AspxToPdf code.

Some of the Features of Chrome Pdf Rendering Feature are:

  1. High-Quality Rendering
    1. The latest “Blink!” HTML rendering. Choose from Chrome Identical rendering or Enhanced Rendering
  2. 20% Faster Renders
    1. Provides effortless multithreading and Async, using as many CPU cores as you wish. For SAAS and high-load applications, this may be 5-20 times faster, outperforming direct browser usage and web-drivers.
  3. Full Support
    1. Full (and we mean full) support for JavaScript, responsive layout and CSS3.
    2. Azure as a first-class citizen. It just works.
    3. Continued maintenance and improved full support for .NET 6, 5, Core, and Framework 4.0+.
  4. Rigorously Tested
    1. The release passed with 1156 green units & integration tests (and no red ones). We believe this EAP to be as stable as our main release, and it has our best minds actively improving it every day.
  5. Section 508 Accessibility Compliance

Produces accessible PDFs using the PDF(UA) tagged PDF standard.

You can use the IronPdf.Rendering.AdaptivePdfRenderer to switch between the ‘Chrome’ and ‘WebKit’ rendering in an instance. If you preferred the old rendering style for some of your applications, or don't want to break unit tests. Multithreading and Async support for our Chrome rendering engine is in a different league to the previous build.

  1. For enterprise-grade multithreading, use our ChromePdfRenderer in your existing threads and it will work. For web applications, this also takes zero setup.
  2. For batch processing of HTML to PDF, we recommend using the built-in .NET Parallel.ForEach pattern.
  3. We love async and have provided Async variants of all of our rendering methods such as ChromePdfRenderer.RenderHtmlAsPdfAsync

Here is an example:

IChromePdfRenderer Renderer = new ChromePdfRenderer();
            Renderer.RenderingOptions.FitToPaper = true;
            Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen;
            Renderer.RenderingOptions.PrintHtmlBackgrounds = true;
            Renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
            using var doc = Renderer.RenderHtmlAsPdf("<h1>Hello world! This is sample for IronPdf</h1>");

            doc.SaveAs("google_chrome.pdf");
IChromePdfRenderer Renderer = new ChromePdfRenderer();
            Renderer.RenderingOptions.FitToPaper = true;
            Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen;
            Renderer.RenderingOptions.PrintHtmlBackgrounds = true;
            Renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
            using var doc = Renderer.RenderHtmlAsPdf("<h1>Hello world! This is sample for IronPdf</h1>");

            doc.SaveAs("google_chrome.pdf");
Dim Renderer As IChromePdfRenderer = New ChromePdfRenderer()
			Renderer.RenderingOptions.FitToPaper = True
			Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen
			Renderer.RenderingOptions.PrintHtmlBackgrounds = True
			Renderer.RenderingOptions.CreatePdfFormsFromHtml = True
			Dim doc = Renderer.RenderHtmlAsPdf("<h1>Hello world! This is sample for IronPdf</h1>")

			doc.SaveAs("google_chrome.pdf")
VB   C#
CSharp Create PDF

15. Summary

Thanks for reading! In this article, we have learned how to create a PDF document in C# using IronPDF. IronPDF is ideal for users needing to convert the contents of HTML to PDF without using HTML tags because of its ease of use and additional features like using JavaScript, CSS, and images.

So, try out these methods and leave your feedback in the comments section of this article post! If you are not yet an IronPDF customer, you can try 30-day free trial to check out their available features.

If you buy the complete Iron Suite, you will get all 5 Products for the Price of 2. For further details about the licensing, please follow this link to Purchase the complete Package.


Library Quick Access

Read API Reference

IronPDF documentation available in the interactive API Reference.

Read API Reference