Drazen Bjelovuk
Drazen Bjelovuk

Reputation: 5492

RuntimeWorkerException: Invalid nested tag head found, expected closing tag meta

I'm using iText in order to convert html into a pdf, but I keep getting a RuntimeWorkerException thrown at parseXHtml. Here's my code:

Document tempDoc = new Document();
PdfWriter pdfWriter = PdfWriter.getInstance(tempDoc, out);
tempDoc.open();
XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, tempDoc, new ByteArrayInputStream(html.getBytes()));
tempDoc.close();

I'm not too familiar with the differences between HTML and XHTML, so I'm at a bit of a loss as to how I should handle this. Here's the html source if it helps.

Upvotes: 6

Views: 35027

Answers (5)

Flavio Troia
Flavio Troia

Reputation: 2809

Remember to close all meta tags

<meta ... />

Upvotes: 1

shivraj kumar
shivraj kumar

Reputation: 1

you have to close each and every tag. example- in HTML

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

is valid.

But in xhtml you have to use

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>

So close each and every tag in html (example meta tag, col tag, img tag etc).

Upvotes: 0

Yair Segal
Yair Segal

Reputation: 120

For a similar error message -

invalid nested tag body found, expected closing tag meta

turned out the XHTML I was parsing had a <script> section at the bottom, that contained JS code, something like:

<script>
  function my_func(var) {
    ...
  }     
</script>

After removing that code (with simple string manipulations), I was able to get the .parseXHtml to work without issues.

Upvotes: 0

saktiprasad swain
saktiprasad swain

Reputation: 340

If you are using XMLWorkerHelper make sure you end image, breakpoint tag properly like />.

Upvotes: 0

Chris Haas
Chris Haas

Reputation: 55457

The error message is pretty clear, you have a <meta> tag in the header that isn't closed which is valid in HTML but not XHTML which is what you are parsing it as. You need to close those, <meta ... />

Upvotes: 19

Related Questions