问题描述:

Here is my code:

Dim sr As StreamReader = New StreamReader(args(0))

Dim htmlStr As String = sr.ReadToEnd

sr.Close()

Using document As Document = New Document()

Using writer As PdfWriter = PdfWriter.GetInstance(document, New FileStream("C:\Test\myfile.pdf", FileMode.Create))

document.Open()

XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, New StringReader(htmlStr)) <--Error here

End Using

document.Close()

End Using

Can anyone help me figure out what can I do to fix this? The htm file I am reading looks fine and also there is nothing I can do to change the file itself.

网友答案:

The error message explains what is going wrong: the error is in your HTML.

You have a <p> tag somewhere, and it is followed by another closing tag (only you can tell us which tag) that is not </p>.

For instance:

This would be correct [1]:

<p>This is a paragraph<br />with a new line</p>

However, this would be incorrect [2]:

<p>This is a paragraph</br>with an incorrect new line</p>

This is also invalid [3]:

<b>Some bold text <p>inside a paragraph</b> that is not correctly nested.</p>

The parser will understand [1], but throw the error you get when you have [2] or [3].

相关阅读:
Top