The following code snippet demonstrates how to convert a html file into PDF format using iText library in VB.NET.
[VB.NET CODE STARTS]
First we need to add reference to iTextSharp library.
' Add references Imports System.IO Imports iTextSharp.text Imports iTextSharp.text.pdf ' Read html file to a string Dim sr As StreamReader = New StreamReader("YOUR HTML FILE PATH WIIH NAME") Dim line As String line = sr.ReadToEnd sr.Close() ' Code to convert to pdf Dim doc As New Document(PageSize.LETTER, 80, 50, 30, 65) Dim fsNew As New StringReader(line) Dim document As New Document(PageSize.A4, 80, 50, 30, 65) Using fs As New FileStream("YOUR PDF FILE PATH WITH NAME", FileMode.Create) PdfWriter.GetInstance(document, fs) Using stringReader As New StringReader(line) Dim parsedList As System.Collections.Generic.List(Of IElement) = html.simpleparser.HTMLWorker.ParseToList(stringReader, Nothing) document.Open() ' parse each html object and add it to the pdf document For Each item As Object In parsedList document.Add(DirectCast(item, IElement)) Next document.Close() End Using End Using
[VB.NET CODE ENDS]