Create PDF in C#Photo by Danny Meneses

Originally Posted On: https://ironpdf.com/docs/questions/create-pdf-csharp/

 

As HTML is 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 and images.

Code Examples

Create PDF from HTMLVB  C#

  1. using System;
  2. using System.Windows.Forms;
  3. using IronPdf;
  4. namespace TestIronPDF1
  5. {
  6. public partial class Form1 : Form
  7. {
  8. public Form1()
  9. {
  10. InitializeComponent();
  11. var HtmlLine = new HtmlToPdf();
  12. HtmlLine.RenderHtmlAsPdf(“

    A Simple PDF File

    Heading 6

    ”).SaveAs(“sample.pdf”);

  13. }
  14. }
  15. }

Copy code to clipboardJump to Article Try IronPDF free for development  Download Free

C# PDF Creator

 

 

Step 1

1. Use the IronPDF C# Library

Use the IronPDF C# library to access the simple HTML to PDF method. The software is available free for development, either via direct download DLL ZIP file or using NuGet command.

Get IronPDF loaded and we can start creating PDFs in C#.

PM > Install-Package IronPdf

 

 

How to Tutorial

2. C# Create PDF

To create a PDF from HTMl, we can take either a HTML page (offline or online, both get converted and replicated on a PDF.) Users can either use .HTML as a link to it, or else it will write a code on double parenthesis with the HTML tags.

In the below example, we have use IronPDF and the method ‘RenderHtmlAsPdf(“”)’ to convert the HTML to a PDF using some HTML tags. This is a very clean one line of code which let you convert into PDF in one go.

  1. using System;
  2. using System.Windows.Forms;
  3. using IronPdf;
  4. namespace TestIronPDF1
  5. {
  6. public partial class Form1 : Form
  7. {
  8. public Form1()
  9. {
  10. InitializeComponent();
  11. var HtmlLine = new HtmlToPdf();
  12. HtmlLine.RenderHtmlAsPdf(“

    A Simple PDF File

    Heading 6

    ”).SaveAs(“sample.pdf”);

  13. }
  14. }
  15. }

Copy code to clipboardVB  C#

 

 

3. View PDF Output

Here is the output in a .PDF format. It’s a very simple converter to get the job completed quickly and efficiently. No bugs, just direct output.