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#
- using System;
- using System.Windows.Forms;
- using IronPdf;
- namespace TestIronPDF1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- var HtmlLine = new HtmlToPdf();
- HtmlLine.RenderHtmlAsPdf(“<h1> A Simple PDF File </h1> <br> <h6> Heading 6 </h6>”).SaveAs(“sample.pdf”);
- }
- }
- }
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(“<TAG>”)’ 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.
- using System;
- using System.Windows.Forms;
- using IronPdf;
- namespace TestIronPDF1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- var HtmlLine = new HtmlToPdf();
- HtmlLine.RenderHtmlAsPdf(“<h1> A Simple PDF File </h1> <br> <h6> Heading 6 </h6>”).SaveAs(“sample.pdf”);
- }
- }
- }
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.