How to C# HTML to PDF
For developers, some professional .NET PDF components can help them easily convert HTML to PDF by using C#. Spire.PDF is one of them. With Spire.PDF, users can use C# to convert files from HTML to PDF effortlessly. Download Spire.PDF, make sure Spire.PDF and Visual Studio are correctly installed on system. Follow the simple instructions below to C# HTML to PDF.
Step 1 Create Project
Create a C# project in Visual Studio and Add Spire.Pdf.dll as reference. The default setting of Spire.Pdf.dll is placed under "C:\Program Files\e-iceblue\Spire.Pdf\Bin”. Select assembly Spire.Pdf.dll and click OK to add it to the project. If your project is not in single thread, you need add [STAThread] before the main method.
using System;
using Spire.Pdf;
namespace HTMLtoPDF
{
class Program
{
[STAThread]
static void Main(string[] args)
{
}
}
}
Step 2 Create a PDF
We need create a blank PDF document in which we can convert HTML content in.
//Create a pdf document.
PdfDocument doc = new PdfDocument();
Step 3 C# HTML to PDF
We can directly convert HTML to PDF from link url.
String url = "http://www.e-iceblue.com";
doc.LoadFromHTML(url, false, true, true);
Step 4 Save and Preview
Save the output file as PDF format and preview it by using the following code:
//Save pdf file.
doc.SaveToFile("FromHTML.pdf");
doc.Close();
//Launching the Pdf file.
System.Diagnostics.Process.Start("FromHTML.pdf");
Effective Screenshot:
Spire.PDF can not only help developers Convert HTML to PDF via C#/VB.NET. As a PDF document creation component, Spire.PDF enables your .NET/Silverlight applications to read, write and manipulate PDF documents without using Adobe Acrobat. Click to learn more…