Because the wonderful reading effect of PDF documents, people would like to convert their electronic documents to PDF, especially articles and papers. Besides it, the other advantage of PDF document is that it can include lots of contents which can make our document be more appealed to readers, for example, comic images, audio, even video. In this post, I will introduce a method to convert HTML to PDF by using C# and VB.NET. It doesn’t means to convert a HTML file to PDF, but the contents in one webpage to a PDF document.
Sometimes, we want to introduce a website to others, such as own homepage or blog in PDF. Just with a hyperlink, people will have no interest with it, while, if we present the contents in this website, people may feel better. At that time, we need to convert this website to PDF.
Following, the method I will give is very simple because I use a .NET PDF component, Spire.PDF for .NET. Therefore, before starting with coding, I add its dll file as reference in my project. After everything is prepared, we can go to steps.
- Create a blank PDF document
- Save and launch file.
Main Coding (C#):
static void Main(string args)
PdfDocument doc = new PdfDocument();
String url = “http://www.google.com/”;
doc.LoadFromHTML(url, false, true, true);
Friend Class fromhtml
Shared Sub Main(ByVal args() As String)
‘Create PDF Document
Dim doc As New PdfDocument()
Dim page As PdfPageBase = doc.Pages.Add()
Dim url As String = “http://www.google.com/”
doc.LoadFromHTML(url, False, True, True)
Result Shown by Following: