0

Sorry for being newbie on this . But Im having an error when it comes to parsing part of my codes.Please help me. The version of my itextsharp is version 4.1.6

Unable to cast object of type 'iTextSharp.text.html.simpleparser.IncTable' to type 'iTextSharp.text.IElement'.

this is my vb codes:

Dim strHTMLContent As StringBuilder = New StringBuilder()
Dim strFinalHTML As String
Dim output = New MemoryStream()
Dim document = New iTextSharp.text.Document(PageSize.A4, 50, 50, 25, 25)
Dim dsRcpComp As New DataSet
Dim dtDetails As New DataTable

Dim RecipeName As String = ""
Dim RecipeIngredients As String = ""

dsRcpComp = GetRcpCompStandard(conStr, CodeListe, CodeTrans)
dtDetails = dsRcpComp.Tables(0)
RecipeName = Replace(dtDetails.Rows(0).Item("Name"), vbCr, "<br>")
RecipeIngredients = Replace(dtDetails.Rows(0).Item("Ingredients"), vbCr, "<br>")

strHTMLContent.Append("<table width=700 align='center' Border='0' cellspacing='50' fontsize='1' class='pdfFont'")
strHTMLContent.Append("<tr>")

'*** GERMAN COLUMN ***
strHTMLContent.Append("<td valign=top><table width=210 align='left'>")
strHTMLContent.Append("<tr><td><font size='2' >" & RecipeName & "</font></td></tr>")
strHTMLContent.Append("<tr><td></td></tr>")

strHTMLContent.Append("<tr><td>")
strHTMLContent.Append(RecipeIngredients & "<br><br>")
strHTMLContent.Append("</td></tr>")

strHTMLContent.Append("</tr></table>")

Dim styles As StyleSheet = New StyleSheet
styles.LoadStyle("pdfFont", "face", "courier")

strFinalHTML = Replace(strHTMLContent.ToString, "& ", "&amp;&nbsp;")

document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate())

Dim parsedHtmlElements = HTMLWorker.ParseToList(New StringReader(strFinalHTML), styles)
Dim writer = PdfWriter.GetInstance(document, output)

document.Open()

For Each htmlElement In parsedHtmlElements
    document.Add(TryCast(htmlElement, IElement))
Next

document.Close()

Return output

I'm getting the error in this line:

Dim parsedHtmlElements = HTMLWorker.ParseToList(New StringReader(strFinalHTML), styles)
Mark
  • 8,140
  • 1
  • 14
  • 29
KeenEgs
  • 35
  • 1
  • 9
  • possible duplicate of [ItextSharp Error on trying to parse html for pdf conversion](http://stackoverflow.com/questions/12113425/itextsharp-error-on-trying-to-parse-html-for-pdf-conversion) – Chris Haas Dec 10 '14 at 06:14
  • he use c#.. Im using vb. – KeenEgs Dec 10 '14 at 07:38
  • 2
    Same difference. The answer also applies to you: (1) you are using an obsolete version of iTextSharp, which means you should upgrade. (as you are new to iTextSharp, why wouldn't you start by using the latest version?) (2) you are using `HTMLWorker`, whereas you should use XML Worker. – Bruno Lowagie Dec 10 '14 at 12:08

0 Answers0